The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
ci(site): IndexNow on every push that changes docs/
purpledfe45f019127
diff --git a/.github/indexnow/indexnow_docs.py b/.github/indexnow/indexnow_docs.pynew file mode 100644index 00000000..2a7d2eea--- /dev/null+++ b/.github/indexnow/indexnow_docs.py@@ -0,0 +1,173 @@+#!/usr/bin/env python3+"""Tell IndexNow which pages of locallyuncensored.com a push changed.++The site is GitHub Pages from master:/docs. IndexNow is the protocol Bing,+Yandex, Seznam and Naver share for "this URL is new, changed or gone, come+and look". Google does not take it; for Google the sitemap and Search Console+stay the way.++Run by .github/workflows/indexnow.yml on every push to master that touches+docs/. It maps the changed .html files of the push to their public URLs,+waits until GitHub Pages serves the new version of one of them, and submits+the list once. Deleted and renamed-away pages go in too: the engines recrawl,+see the 404 and drop them.++The key is public by design: the protocol proves ownership by serving it at+https://locallyuncensored.com/<key>.txt (docs/). Never rotate it.++Only the standard library, so the workflow needs no install step.+"""++from __future__ import annotations++import argparse+import json+import subprocess+import sys+import time+import urllib.error+import urllib.request++HOST = "locallyuncensored.com"+KEY = "64c8084e74dd0e16c6152f82363537ad"+KEY_LOCATION = f"https://{HOST}/{KEY}.txt"+ENDPOINT = "https://api.indexnow.org/indexnow"+MAX_URLS = 10_000+ZERO_SHA = "0" * 40+# Pages that are not meant to be found.+SKIP = {"docs/404.html"}+++def url_for(path: str) -> str | None:+ """docs/blog/x.html -> https://host/blog/x.html, docs/guide/index.html -> https://host/guide/"""+ if not path.startswith("docs/") or not path.endswith(".html") or path in SKIP:+ return None+ rel = path[len("docs/"):]+ if rel == "index.html":+ rel = ""+ elif rel.endswith("/index.html"):+ rel = rel[: -len("index.html")]+ return f"https://{HOST}/{rel}"+++def parse_name_status(text: str) -> tuple[list[str], list[str]]:+ """git diff --name-status output -> (paths that exist after the push, paths that are gone)."""+ present: list[str] = []+ gone: list[str] = []+ for line in text.splitlines():+ parts = line.split("\t")+ if len(parts) < 2:+ continue+ status = parts[0]+ if status.startswith("R"): # rename: old path gone, new path present+ gone.append(parts[1])+ present.append(parts[2])+ elif status.startswith("C"):+ present.append(parts[2])+ elif status == "D":+ gone.append(parts[1])+ else: # A, M, T+ present.append(parts[1])+ return present, gone+++def is_noindex(html: str) -> bool:+ head = html.split("</head>", 1)[0].lower()+ return 'name="robots"' in head and "noindex" in head+++def collect(present: list[str], gone: list[str], read) -> list[str]:+ """Public URLs to submit. `read(path)` returns the file at the pushed commit."""+ urls: list[str] = []+ for path in present:+ url = url_for(path)+ if url and not is_noindex(read(path)):+ urls.append(url)+ for path in gone:+ url = url_for(path)+ if url:+ urls.append(url)+ seen: set[str] = set()+ return [u for u in urls if not (u in seen or seen.add(u))][:MAX_URLS]+++def body(urls: list[str]) -> dict:+ return {"host": HOST, "key": KEY, "keyLocation": KEY_LOCATION, "urlList": urls}+++def git(*args: str) -> str:+ return subprocess.run(["git", *args], check=True, capture_output=True, text=True).stdout+++def changed_paths(before: str, after: str) -> tuple[list[str], list[str]]:+ base = before+ if not base or base == ZERO_SHA or subprocess.run(+ ["git", "cat-file", "-e", f"{base}^{{commit}}"], capture_output=True+ ).returncode != 0:+ base = f"{after}^"+ return parse_name_status(git("diff", "--name-status", "-M", base, after, "--", "docs/"))+++def wait_until_live(url: str, expected: bytes, timeout_s: int) -> bool:+ """GitHub Pages builds after the push; submit only once the new file is served."""+ deadline = time.time() + timeout_s+ while time.time() < deadline:+ try:+ req = urllib.request.Request(url, headers={"Cache-Control": "no-cache", "User-Agent": "lu-indexnow"})+ with urllib.request.urlopen(req, timeout=20) as res:+ if res.read() == expected:+ return True+ except urllib.error.URLError:+ pass+ time.sleep(15)+ return False+++def submit(urls: list[str]) -> int:+ req = urllib.request.Request(+ ENDPOINT,+ data=json.dumps(body(urls)).encode(),+ headers={"Content-Type": "application/json; charset=utf-8"},+ method="POST",+ )+ try:+ with urllib.request.urlopen(req, timeout=30) as res:+ return res.status+ except urllib.error.HTTPError as err:+ print(f"IndexNow answered HTTP {err.code}: {err.read()[:300]!r}", file=sys.stderr)+ return err.code+++def main() -> int:+ ap = argparse.ArgumentParser()+ ap.add_argument("--before", default="")+ ap.add_argument("--after", default="HEAD")+ ap.add_argument("--dry-run", action="store_true")+ ap.add_argument("--wait", type=int, default=600, help="seconds to wait for GitHub Pages")+ args = ap.parse_args()++ present, gone = changed_paths(args.before, args.after)+ urls = collect(present, gone, lambda p: git("show", f"{args.after}:{p}"))+ if not urls:+ print("No public page changed, nothing to submit.")+ return 0+ print(f"{len(urls)} URL(s):", *urls, sep="\n ")+ if args.dry_run:+ print(json.dumps(body(urls), indent=2))+ return 0++ probe = next((p for p in present if url_for(p)), None)+ if probe and args.wait > 0:+ expected = subprocess.run(["git", "show", f"{args.after}:{probe}"], check=True, capture_output=True).stdout+ if wait_until_live(url_for(probe), expected, args.wait):+ print(f"Live: {url_for(probe)}")+ else:+ print(f"::warning::{url_for(probe)} not live after {args.wait}s, submitting anyway")++ status = submit(urls)+ print(f"IndexNow HTTP {status}")+ return 0 if status in (200, 202) else 1+++if __name__ == "__main__":+ sys.exit(main())diff --git a/.github/indexnow/test_indexnow_docs.py b/.github/indexnow/test_indexnow_docs.pynew file mode 100644index 00000000..e23a503a--- /dev/null+++ b/.github/indexnow/test_indexnow_docs.py@@ -0,0 +1,59 @@+"""python3 -m unittest discover -s .github/indexnow -p 'test_indexnow_docs.py'"""++import os+import sys+import unittest++sys.path.insert(0, os.path.dirname(__file__))+import indexnow_docs as ix # noqa: E402+++class UrlFor(unittest.TestCase):+ def test_pages(self):+ self.assertEqual(ix.url_for("docs/index.html"), "https://locallyuncensored.com/")+ self.assertEqual(ix.url_for("docs/guide/index.html"), "https://locallyuncensored.com/guide/")+ self.assertEqual(ix.url_for("docs/guide/install/index.html"), "https://locallyuncensored.com/guide/install/")+ self.assertEqual(ix.url_for("docs/blog/x.html"), "https://locallyuncensored.com/blog/x.html")++ def test_not_pages(self):+ for p in ["docs/404.html", "docs/sitemap.xml", "docs/assets/a.css", "src/index.html", "docs/llms.txt"]:+ self.assertIsNone(ix.url_for(p), p)+++class NameStatus(unittest.TestCase):+ def test_add_modify_delete_rename(self):+ present, gone = ix.parse_name_status(+ "A\tdocs/blog/new.html\nM\tdocs/index.html\nD\tdocs/blog/old.html\nR087\tdocs/a.html\tdocs/b.html\n"+ )+ self.assertEqual(present, ["docs/blog/new.html", "docs/index.html", "docs/b.html"])+ self.assertEqual(gone, ["docs/blog/old.html", "docs/a.html"])+++class Collect(unittest.TestCase):+ def test_noindex_pages_stay_out_and_gone_pages_go_in(self):+ files = {+ "docs/blog/new.html": "<html><head><title>x</title></head></html>",+ "docs/hidden.html": '<html><head><meta name="robots" content="noindex"></head></html>',+ "docs/sitemap.xml": "<urlset/>",+ }+ urls = ix.collect(+ ["docs/blog/new.html", "docs/hidden.html", "docs/sitemap.xml"],+ ["docs/blog/old.html", "docs/blog/new.html"],+ files.__getitem__,+ )+ self.assertEqual(+ urls,+ ["https://locallyuncensored.com/blog/new.html", "https://locallyuncensored.com/blog/old.html"],+ )++ def test_body_names_the_served_key(self):+ b = ix.body(["https://locallyuncensored.com/"])+ self.assertEqual(b["host"], "locallyuncensored.com")+ self.assertEqual(b["keyLocation"], f"https://locallyuncensored.com/{ix.KEY}.txt")+ root = os.path.join(os.path.dirname(__file__), "..", "..", "docs", f"{ix.KEY}.txt")+ with open(root) as f:+ self.assertEqual(f.read().strip(), ix.KEY)+++if __name__ == "__main__":+ unittest.main()diff --git a/.github/workflows/indexnow.yml b/.github/workflows/indexnow.ymlnew file mode 100644index 00000000..b4b72d66--- /dev/null+++ b/.github/workflows/indexnow.yml@@ -0,0 +1,32 @@+name: IndexNow++# Every push to master that changes the website (docs/, served by GitHub Pages)+# tells IndexNow which pages are new, changed or gone, so Bing (and Yandex,+# Seznam, Naver) look within minutes instead of at the next crawl. Google does+# not take IndexNow. The script waits until Pages serves the new version+# before it submits. See .github/indexnow/indexnow_docs.py.+on:+ push:+ branches: [master]+ paths: ['docs/**']+ workflow_dispatch:++concurrency:+ group: indexnow+ cancel-in-progress: false++permissions:+ contents: read++jobs:+ submit:+ runs-on: ubuntu-latest+ timeout-minutes: 15+ steps:+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2+ with:+ fetch-depth: 0+ - name: Test the URL mapping+ run: python3 -I -m unittest discover -s .github/indexnow -p 'test_indexnow_docs.py'+ - name: Submit changed pages+ run: python3 -I .github/indexnow/indexnow_docs.py --before "${{ github.event.before }}" --after "${{ github.sha }}"diff --git a/.gitignore b/.gitignoreindex b3a5a5a4..4de57bd1 100644--- a/.gitignore+++ b/.gitignore@@ -206,3 +206,5 @@ service-account*.json# (INTEGRATION-306.md is one). Without this line a new note with such a name# would be left out without a word. Must stay below the block above.!/mobile-docs/**/*.md++__pycache__/