Baue die Doku-Quellen als statische MkDocs-Seite

Andreas 04.09.: SilverBullet ist für die Doku nicht das Richtige — die
Doku soll aussehen wie sie soll, lesen statt editieren, und ohne
Auto-Commit-Problem. km baut deshalb je Quelle mit mkdocs.yml nach jedem
Pull mit Änderung eine statische Seite nach <data>/site/<name>; Caddy
liefert sie unter /doku/<name>/ aus. Ein Baufehler lässt die alte Seite
stehen und wird im Lauf gemeldet. Image bekommt mkdocs-material.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-09-04 19:58:57 +02:00
co-authored by Claude Fable 5.1
parent 91a4d8c8a6
commit 125a8b9c0f
2 changed files with 27 additions and 0 deletions
+25
View File
@@ -8,6 +8,7 @@ laufen nie gleichzeitig -- der zweite wartet.
from __future__ import annotations
import subprocess
import sys
import threading
import time
@@ -43,9 +44,13 @@ class Runner:
if src.commit_all("km: Änderungen aus der Oberfläche"):
src.push()
result[f"commit_{src.name}"] = src.head()
before = src.head()
src.pull()
if src.last_push_error:
result[f"push_fehler_{src.name}"] = src.last_push_error
built = self._build_site(src, changed=src.head() != before)
if built:
result[f"site_{src.name}"] = built
result["ingest"] = self._ingest(full)
result["index"] = self._index()
if self.ablage.commit_all(self._message(result)):
@@ -86,6 +91,26 @@ class Runner:
out["fehler"] = fehler
return out
def _build_site(self, src, changed: bool) -> str | None:
"""Statische Seite einer Quelle mit MkDocs bauen (Andreas 04.09.: die Doku
soll aussehen wie sie soll -- lesen, nicht editieren). Gebaut wird nach
<data>/site/<name>, wenn die Quelle ein mkdocs.yml hat und sich seit dem
letzten Bau etwas getan hat. Ein Fehler beim Bau laesst die alte Seite
stehen und wird gemeldet, statt den Takt zu reissen."""
if not (src.path / "mkdocs.yml").exists():
return None
out = self.cfg.ablage.parent / "site" / src.name
if not changed and (out / "index.html").exists():
return None
t0 = time.time()
r = subprocess.run([sys.executable, "-m", "mkdocs", "build", "-q", "-d", str(out)],
cwd=src.path, capture_output=True, text=True, timeout=600)
if r.returncode != 0:
msg = (r.stderr or r.stdout).strip()[-400:]
print(f"km: mkdocs {src.name}: {msg}", file=sys.stderr, flush=True)
return f"FEHLER: {msg[-120:]}"
return f"gebaut in {time.time() - t0:.0f}s ({src.head()})"
def _index(self) -> dict:
c = self.cfg
con = km_index.connect(c.db)
+2
View File
@@ -1,2 +1,4 @@
requests>=2.31
sqlite-vec>=0.1.6
mkdocs-material>=9.5
pymdown-extensions>=10