From 01874a664a4011b5af04ba33e91c7789fefedc31 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 22:56:51 +0000 Subject: [PATCH 1/6] The documentation site built with Zensical and published on GitHub Pages from each push to main; the links that leave docs/ rewritten by a Markdown extension, since Zensical runs no hooks Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QUxVfokgChbTg66bZpiQJ7 --- .github/workflows/docs.yml | 30 ++++++++++++++++++++++++++++++ code/docs/README.md | 11 +++++++---- code/docs/site_links.py | 23 ++++++++++++++++++++--- mkdocs.yml | 7 ++++--- tests/test_docs_site.py | 4 ++-- 5 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..2951a9d --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,30 @@ +name: Documentation +on: + push: + branches: + - main +permissions: + contents: read + pages: write + id-token: write +jobs: + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - uses: actions/configure-pages@v6 + - uses: actions/checkout@v7 + - uses: actions/setup-python@v6 + with: + python-version: 3.x + - run: pip install zensical==0.1.5 + - run: zensical build --clean --strict + env: + PYTHONPATH: code/docs + - uses: actions/upload-pages-artifact@v5 + with: + path: site + - uses: actions/deploy-pages@v5 + id: deployment diff --git a/code/docs/README.md b/code/docs/README.md index 87d5874..2e4af61 100644 --- a/code/docs/README.md +++ b/code/docs/README.md @@ -16,14 +16,17 @@ The histology figures read the JPEG 2000 sections and need `$PY_TIRL`; the other ## The documentation site -`mkdocs.yml`, at the top of the repository, builds the pages of `docs/` into a site as they are: a home page, the overview, the tutorials, the how-to pages, the brain identifiers, the FAQ and troubleshooting, with a search box. +[Zensical](https://zensical.org) reads `mkdocs.yml`, at the top of the repository, and builds the pages of `docs/` into a site as they are: a home page, the overview, the tutorials, the how-to pages, the brain identifiers, the FAQ and troubleshooting, with a search box. ```text -pip install mkdocs-material in any Python environment; the pipeline's environments do not need it -mkdocs build --strict writes site/; stops at a broken link or a link to a heading that does not exist -mkdocs serve shows the site on this machine while you edit +pip install zensical==0.1.5 in any Python environment; the pipeline's environments do not need it +PYTHONPATH=code/docs zensical build --strict writes site/ +PYTHONPATH=code/docs zensical serve shows the site on this machine while you edit ``` +Each push to `main` builds the site and publishes it on GitHub Pages (`.github/workflows/docs.yml`). + The pages keep their relative links, so they read the same on GitHub. `site_links.py` sends the links that leave `docs/`, to the code, the settings or the tests, to the same file on GitHub. +Zensical checks links before `site_links.py` rewrites them, so its link check is off in `mkdocs.yml`; `tests/test_docs_site.py` checks that every relative link leads to a file. A new page goes into the `nav` list of `mkdocs.yml`; `tests/test_docs_site.py` says so if it is missing. diff --git a/code/docs/site_links.py b/code/docs/site_links.py index 5e66c4a..1dfcf67 100644 --- a/code/docs/site_links.py +++ b/code/docs/site_links.py @@ -2,7 +2,7 @@ tests, goes to that file in the repository on GitHub. You need - nothing: MkDocs loads this file itself (mkdocs.yml, `hooks`). + nothing: Zensical loads this file itself (mkdocs.yml, `markdown_extensions`), with code/docs on PYTHONPATH. What it does The Markdown files keep their relative links, which GitHub follows as they are. A site built from docs/ holds only docs/, so on each page a link whose target is outside docs/ is rewritten to https://github.com/lincbrain/fiber_template/blob/main/. @@ -26,9 +26,26 @@ def outside(page_path, url): return None if target == "docs" or target.startswith("docs/") else target + sep + anchor -def on_page_markdown(markdown, page, **kwargs): +def rewrite(markdown, page_path): def fix(m): - target = outside(page.file.src_uri, m.group(2)) + target = outside(page_path, m.group(2)) return m.group(0) if target is None else f"[{m.group(1)}]({REPO}{target})" return LINK.sub(fix, markdown) + + +def makeExtension(**kwargs): + from markdown import Extension + from markdown.preprocessors import Preprocessor + from zensical.extensions.context import ContextPreprocessor + + class SiteLinks(Preprocessor): + def run(self, lines): + page = ContextPreprocessor.from_markdown(self.md).page + return rewrite("\n".join(lines), page.path).split("\n") + + class SiteLinksExtension(Extension): + def extendMarkdown(self, md): + md.preprocessors.register(SiteLinks(md), "site_links", 40) + + return SiteLinksExtension(**kwargs) diff --git a/mkdocs.yml b/mkdocs.yml index d58aa54..3458ec3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,11 +12,12 @@ theme: - navigation.sections - navigation.top - content.code.copy -hooks: - - code/docs/site_links.py # a link that leaves docs/ goes to that file on GitHub +markdown_extensions: + - site_links # a link that leaves docs/ goes to that file on GitHub validation: links: - anchors: warn # with --strict, a link to a heading that does not exist stops the build + not_found: ignore + anchors: ignore nav: - Home: README.md - Overview: overview.md diff --git a/tests/test_docs_site.py b/tests/test_docs_site.py index f45b22d..77ab84a 100644 --- a/tests/test_docs_site.py +++ b/tests/test_docs_site.py @@ -1,4 +1,4 @@ -"""Tests of the documentation site's settings (mkdocs.yml) against the pages of docs/ (CPU, no data, MkDocs not needed). +"""Tests of the documentation site's settings (mkdocs.yml) against the pages of docs/ (CPU, no data, Zensical not needed). python -m pytest tests/test_docs_site.py or python tests/run.py tests/test_docs_site.py @@ -44,7 +44,7 @@ def hook(): def test_the_menu_names_every_page(): cfg = site() - assert cfg["docs_dir"] == "docs" and all((REPO / h).is_file() for h in cfg["hooks"]) + assert cfg["docs_dir"] == "docs" and "site_links" in cfg["markdown_extensions"] pages = menu(cfg["nav"]) assert pages and all((DOCS / p).is_file() for p in pages), [p for p in pages if not (DOCS / p).is_file()] notes = {p.relative_to(DOCS).as_posix() for p in DOCS.rglob("README.md")} - {"README.md"} # a subfolder's own note From 8fd7de6b68914d69f30345187ccc3ffa94f878f2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 04:25:20 +0000 Subject: [PATCH 2/6] The Markdown extension for the documentation site in its own file, site_links_extension.py, with its imports at the top; site_links.py keeps the rule alone, so the test still loads it without Markdown or Zensical Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QUxVfokgChbTg66bZpiQJ7 --- code/docs/README.md | 2 +- code/docs/site_links.py | 19 +------------------ code/docs/site_links_extension.py | 23 +++++++++++++++++++++++ mkdocs.yml | 2 +- tests/test_docs_site.py | 2 +- 5 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 code/docs/site_links_extension.py diff --git a/code/docs/README.md b/code/docs/README.md index 2e4af61..44cbfb4 100644 --- a/code/docs/README.md +++ b/code/docs/README.md @@ -27,6 +27,6 @@ PYTHONPATH=code/docs zensical serve shows the site on this machine Each push to `main` builds the site and publishes it on GitHub Pages (`.github/workflows/docs.yml`). The pages keep their relative links, so they read the same on GitHub. -`site_links.py` sends the links that leave `docs/`, to the code, the settings or the tests, to the same file on GitHub. +`site_links.py` sends the links that leave `docs/`, to the code, the settings or the tests, to the same file on GitHub; `site_links_extension.py` applies it to each page as Zensical builds it. Zensical checks links before `site_links.py` rewrites them, so its link check is off in `mkdocs.yml`; `tests/test_docs_site.py` checks that every relative link leads to a file. A new page goes into the `nav` list of `mkdocs.yml`; `tests/test_docs_site.py` says so if it is missing. diff --git a/code/docs/site_links.py b/code/docs/site_links.py index 1dfcf67..0619ae6 100644 --- a/code/docs/site_links.py +++ b/code/docs/site_links.py @@ -2,7 +2,7 @@ tests, goes to that file in the repository on GitHub. You need - nothing: Zensical loads this file itself (mkdocs.yml, `markdown_extensions`), with code/docs on PYTHONPATH. + nothing: site_links_extension.py applies it to every page. What it does The Markdown files keep their relative links, which GitHub follows as they are. A site built from docs/ holds only docs/, so on each page a link whose target is outside docs/ is rewritten to https://github.com/lincbrain/fiber_template/blob/main/. @@ -32,20 +32,3 @@ def fix(m): return m.group(0) if target is None else f"[{m.group(1)}]({REPO}{target})" return LINK.sub(fix, markdown) - - -def makeExtension(**kwargs): - from markdown import Extension - from markdown.preprocessors import Preprocessor - from zensical.extensions.context import ContextPreprocessor - - class SiteLinks(Preprocessor): - def run(self, lines): - page = ContextPreprocessor.from_markdown(self.md).page - return rewrite("\n".join(lines), page.path).split("\n") - - class SiteLinksExtension(Extension): - def extendMarkdown(self, md): - md.preprocessors.register(SiteLinks(md), "site_links", 40) - - return SiteLinksExtension(**kwargs) diff --git a/code/docs/site_links_extension.py b/code/docs/site_links_extension.py new file mode 100644 index 0000000..63dcd85 --- /dev/null +++ b/code/docs/site_links_extension.py @@ -0,0 +1,23 @@ +"""The Markdown extension through which Zensical applies site_links.py to every page (mkdocs.yml, `markdown_extensions`). +Zensical imports it by name, so code/docs must be on PYTHONPATH. +""" +from markdown import Extension +from markdown.preprocessors import Preprocessor +from zensical.extensions.context import ContextPreprocessor + +from site_links import rewrite + + +class SiteLinks(Preprocessor): + def run(self, lines): + page = ContextPreprocessor.from_markdown(self.md).page + return rewrite("\n".join(lines), page.path).split("\n") + + +class SiteLinksExtension(Extension): + def extendMarkdown(self, md): + md.preprocessors.register(SiteLinks(md), "site_links", 40) + + +def makeExtension(**kwargs): + return SiteLinksExtension(**kwargs) diff --git a/mkdocs.yml b/mkdocs.yml index 3458ec3..2613ddc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,7 +13,7 @@ theme: - navigation.top - content.code.copy markdown_extensions: - - site_links # a link that leaves docs/ goes to that file on GitHub + - site_links_extension # a link that leaves docs/ goes to that file on GitHub validation: links: not_found: ignore diff --git a/tests/test_docs_site.py b/tests/test_docs_site.py index 77ab84a..c1283e1 100644 --- a/tests/test_docs_site.py +++ b/tests/test_docs_site.py @@ -44,7 +44,7 @@ def hook(): def test_the_menu_names_every_page(): cfg = site() - assert cfg["docs_dir"] == "docs" and "site_links" in cfg["markdown_extensions"] + assert cfg["docs_dir"] == "docs" and "site_links_extension" in cfg["markdown_extensions"] pages = menu(cfg["nav"]) assert pages and all((DOCS / p).is_file() for p in pages), [p for p in pages if not (DOCS / p).is_file()] notes = {p.relative_to(DOCS).as_posix() for p in DOCS.rglob("README.md")} - {"README.md"} # a subfolder's own note From 0fb62155d8e8e1484872eededc5efeb0917f3157 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 04:30:54 +0000 Subject: [PATCH 3/6] The documentation site's README says Zensical needs Python 3.11 or newer Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QUxVfokgChbTg66bZpiQJ7 --- code/docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/docs/README.md b/code/docs/README.md index 44cbfb4..dbd166e 100644 --- a/code/docs/README.md +++ b/code/docs/README.md @@ -19,7 +19,7 @@ The histology figures read the JPEG 2000 sections and need `$PY_TIRL`; the other [Zensical](https://zensical.org) reads `mkdocs.yml`, at the top of the repository, and builds the pages of `docs/` into a site as they are: a home page, the overview, the tutorials, the how-to pages, the brain identifiers, the FAQ and troubleshooting, with a search box. ```text -pip install zensical==0.1.5 in any Python environment; the pipeline's environments do not need it +pip install zensical==0.1.5 in any Python 3.11 or newer environment; the pipeline's environments do not need it PYTHONPATH=code/docs zensical build --strict writes site/ PYTHONPATH=code/docs zensical serve shows the site on this machine while you edit ``` From ec7a7245094b640b78f655cbe575b9b3ef6f407f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 04:32:01 +0000 Subject: [PATCH 4/6] The documentation site built on every pull request too, without publishing; only a push to main deploys it Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QUxVfokgChbTg66bZpiQJ7 --- .github/workflows/docs.yml | 22 +++++++++++++++------- code/docs/README.md | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2951a9d..58ce1e7 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -3,18 +3,13 @@ on: push: branches: - main + pull_request: permissions: contents: read - pages: write - id-token: write jobs: - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} + build: runs-on: ubuntu-latest steps: - - uses: actions/configure-pages@v6 - uses: actions/checkout@v7 - uses: actions/setup-python@v6 with: @@ -24,7 +19,20 @@ jobs: env: PYTHONPATH: code/docs - uses: actions/upload-pages-artifact@v5 + if: github.event_name == 'push' with: path: site + deploy: + if: github.event_name == 'push' + needs: build + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - uses: actions/configure-pages@v6 - uses: actions/deploy-pages@v5 id: deployment diff --git a/code/docs/README.md b/code/docs/README.md index dbd166e..6b8f6f4 100644 --- a/code/docs/README.md +++ b/code/docs/README.md @@ -24,7 +24,7 @@ PYTHONPATH=code/docs zensical build --strict writes site/ PYTHONPATH=code/docs zensical serve shows the site on this machine while you edit ``` -Each push to `main` builds the site and publishes it on GitHub Pages (`.github/workflows/docs.yml`). +Each push to `main` builds the site and publishes it on GitHub Pages; each pull request builds it without publishing (`.github/workflows/docs.yml`). The pages keep their relative links, so they read the same on GitHub. `site_links.py` sends the links that leave `docs/`, to the code, the settings or the tests, to the same file on GitHub; `site_links_extension.py` applies it to each page as Zensical builds it. From 9d6c157f5326b4886e51fb0173132de7040cd3d6 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 04:32:52 +0000 Subject: [PATCH 5/6] The documentation site's address on GitHub Pages in mkdocs.yml, so that the 404 page finds its styles under /fiber_template/ and the sitemap lists the pages Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QUxVfokgChbTg66bZpiQJ7 --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 2613ddc..812f1a3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,6 +1,7 @@ # The documentation site, built from docs/ as it is. How to build it: code/docs/README.md site_name: fiber_template site_description: Code and documentation for a multimodal macaque template that aligns ex vivo MRI and microscopy +site_url: https://lincbrain.github.io/fiber_template/ repo_url: https://github.com/lincbrain/fiber_template repo_name: lincbrain/fiber_template edit_uri: "" From 3b3465a037de1ea146b0533a3db0a65be586cc40 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 3 Dec 2026 04:35:14 +0000 Subject: [PATCH 6/6] The documentation site's test names its loader for site_links.py and checks that site_links_extension.py exists Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QUxVfokgChbTg66bZpiQJ7 --- tests/test_docs_site.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_docs_site.py b/tests/test_docs_site.py index c1283e1..0098e5f 100644 --- a/tests/test_docs_site.py +++ b/tests/test_docs_site.py @@ -35,7 +35,7 @@ def menu(nav): return out -def hook(): +def site_links(): spec = importlib.util.spec_from_file_location("site_links", REPO / "code" / "docs" / "site_links.py") mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) @@ -45,6 +45,7 @@ def hook(): def test_the_menu_names_every_page(): cfg = site() assert cfg["docs_dir"] == "docs" and "site_links_extension" in cfg["markdown_extensions"] + assert (REPO / "code" / "docs" / "site_links_extension.py").is_file() pages = menu(cfg["nav"]) assert pages and all((DOCS / p).is_file() for p in pages), [p for p in pages if not (DOCS / p).is_file()] notes = {p.relative_to(DOCS).as_posix() for p in DOCS.rglob("README.md")} - {"README.md"} # a subfolder's own note @@ -53,7 +54,7 @@ def test_the_menu_names_every_page(): def test_every_relative_link_leads_to_a_file(): - outside, broken, sent = hook().outside, [], 0 + outside, broken, sent = site_links().outside, [], 0 for page in sorted(DOCS.rglob("*.md")): rel = page.relative_to(DOCS).as_posix() text = re.sub(r"```.*?```", "", page.read_text(encoding="utf-8"), flags=re.S)