Repository navigation
feat(site): portal structure and pages, with appinfra as the first package #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,70 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # SPDX-FileCopyrightText: Copyright 2026 The llm-works-docs Authors | ||
|
|
||
| infra := $(shell appinfra scripts-path) | ||
| # Settings use ?= so the environment and a Makefile.local (gitignored, assigned with :=) can | ||
| # override them; `make config` shows where each value came from. | ||
|
|
||
| # Configuration | ||
| APPINFRA_DEV_PKG_NAME := docsite | ||
| APPINFRA_DEV_PKG_NAME ?= docsite | ||
|
|
||
| # Code quality strictness | ||
| # - true: Fail on any code quality violations (CI mode) | ||
| # - false: Report violations but don't fail (development mode) | ||
| APPINFRA_DEV_CQ_STRICT := true | ||
| APPINFRA_DEV_CQ_STRICT ?= true | ||
|
|
||
| # Include SPDX header check in `make check`; the license comes from pyproject.toml (MIT). | ||
| APPINFRA_DEV_CQ_SPDX := true | ||
| APPINFRA_DEV_CQ_SPDX ?= true | ||
|
|
||
| # No ruff rules reported as warnings only: they are enforced in pyproject's select | ||
| APPINFRA_DEV_CQ_LINT_SELECT := false | ||
| APPINFRA_DEV_CQ_LINT_SELECT ?= false | ||
|
|
||
| # Fail on duplicated code blocks and unused private definitions | ||
| APPINFRA_DEV_CQ_DUP := strict | ||
| APPINFRA_DEV_CQ_DEAD := strict | ||
| APPINFRA_DEV_CQ_DUP ?= strict | ||
| APPINFRA_DEV_CQ_DEAD ?= strict | ||
|
|
||
| # Report tests that sit in another suite's directory, or leak process-wide state | ||
| APPINFRA_DEV_TEST_HEALTH := warn | ||
| APPINFRA_DEV_TEST_HEALTH ?= warn | ||
|
|
||
| # Test coverage threshold (percentage), measured over unit and integration tests | ||
| APPINFRA_PYTEST_COVERAGE_THRESHOLD := 95 | ||
| APPINFRA_PYTEST_COVERAGE_MARKERS := unit or integration | ||
| APPINFRA_PYTEST_COVERAGE_THRESHOLD ?= 95 | ||
| APPINFRA_PYTEST_COVERAGE_MARKERS ?= unit or integration | ||
|
|
||
| # Docstring coverage threshold (percentage) | ||
| APPINFRA_DEV_DOCSTRING_THRESHOLD := 90 | ||
|
|
||
| # Include framework (config first). Makefile.docs is left out: it drives MkDocs, and this | ||
| # site is built with Zensical. | ||
| include $(infra)/make/Makefile.config | ||
| include $(infra)/make/Makefile.env | ||
| include $(infra)/make/Makefile.help | ||
| include $(infra)/make/Makefile.utils | ||
| include $(infra)/make/Makefile.dev | ||
| include $(infra)/make/Makefile.pytest | ||
| include $(infra)/make/Makefile.install | ||
| include $(infra)/make/Makefile.clean | ||
| APPINFRA_DEV_DOCSTRING_THRESHOLD ?= 90 | ||
|
|
||
| # Locate the framework once, before the first include; the environment and the command line | ||
| # can still name another copy. | ||
| ifeq ($(origin APPINFRA_SCRIPTS),undefined) | ||
| APPINFRA_SCRIPTS := $(shell appinfra scripts-path) | ||
| endif | ||
|
|
||
| # Include framework (config first: it loads Makefile.local). Makefile.docs is left out: it drives | ||
| # MkDocs, and this site is built with Zensical. | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.config | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.env | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.help | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.utils | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.dev | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.pytest | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.install | ||
| include $(APPINFRA_SCRIPTS)/make/Makefile.clean | ||
|
|
||
| # Site: `python -m docsite build` assembles docs/, the header and zensical.toml from the pinned | ||
| # packages and the main-site nav; Zensical renders them. Build inputs are docsite config in | ||
| # etc/docsite.yaml, overridable per key with INFRA_<SECTION>_<KEY> environment variables (e.g. | ||
| # INFRA_NAV_URL for a local main-site dev server). A Makefile.local exports them to the site | ||
| # targets only (`build serve: export INFRA_NAV_URL := ...`): appinfra's own tools read INFRA_* | ||
| # as well and reject paths their config does not declare. | ||
|
|
||
| # The dev server's address (Zensical's default); set SITE_ADDR := host:port in Makefile.local. | ||
| SITE_ADDR ?= localhost:8000 | ||
|
|
||
| .PHONY: build serve | ||
|
|
||
| build: ## Build the docs site into site/ | ||
| python -m docsite build | ||
| zensical build --clean | ||
|
|
||
| serve: ## Build the site inputs, then serve with live reload on SITE_ADDR (default localhost:8000) | ||
| python -m docsite build | ||
| zensical serve --dev-addr $(SITE_ADDR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # SPDX-FileCopyrightText: Copyright 2026 The llm-works-docs Authors | ||
|
|
||
| """Griffe extension: render indented code in docstrings as code blocks. | ||
|
|
||
| Packages write docstring examples as plain indented blocks under a title, e.g. `Example:`, which | ||
| the Google-style parser hands to Markdown as text: the lines run together into one paragraph and | ||
| a `# comment` becomes a heading. This extension wraps such blocks in fences before parsing. | ||
| Loaded by mkdocstrings from zensical.base.toml as `docsite/docstring_code.py:CodeBlocks`. | ||
| """ | ||
|
|
||
| import ast | ||
| import re | ||
| from typing import Any | ||
|
|
||
| from griffe import Extension, Object | ||
|
|
||
| # A section title alone on its line, e.g. "Example:" or "Include Example:" | ||
| _TITLE = re.compile(r"[A-Z][\w ()/'-]{0,40}:") | ||
| # Titles the Google-style parser reads as structured items, which must stay as they are | ||
| _STRUCTURED = frozenset( | ||
| { | ||
| "args", "arguments", "params", "parameters", "keyword args", "keyword arguments", | ||
| "other args", "other arguments", "other params", "other parameters", "raises", | ||
| "exceptions", "warns", "warnings", "returns", "return", "yields", "yield", "receives", | ||
| "receive", "attributes", "functions", "methods", "classes", "modules", "type aliases", | ||
| "type parameters", "deprecated", | ||
| } | ||
| ) # fmt: skip | ||
| # A line of a YAML mapping or list, or a comment | ||
| _YAML_LINE = re.compile(r"\s*(#.*|[\w.-]+:(\s.*)?|- .*)") | ||
| _EXAMPLE_WORDS = ("example", "usage") | ||
|
|
||
|
|
||
| class CodeBlocks(Extension): | ||
| """Fences titled code blocks in every docstring before the parser sees them.""" | ||
|
|
||
| def on_instance(self, *, obj: Object, **kwargs: Any) -> None: | ||
| """Rewrite the object's docstring text in place.""" | ||
| if obj.docstring is not None: | ||
| obj.docstring.value = fence_code_blocks(obj.docstring.value) | ||
|
|
||
|
|
||
| def fence_code_blocks(text: str) -> str: | ||
| """Return `text` with each titled block of code wrapped in a fenced code block.""" | ||
| lines = text.split("\n") | ||
| out: list[str] = [] | ||
| i = 0 | ||
| while i < len(lines): | ||
| out.append(lines[i]) | ||
| end = _block_end(lines, i) | ||
| block = lines[i + 1 : end] | ||
| if end > i + 1 and _is_code(lines[i].strip()[:-1], block): | ||
| out.extend(_fenced(block)) | ||
| i = end | ||
| else: | ||
| i += 1 | ||
| return "\n".join(out) | ||
|
|
||
|
|
||
| def _block_end(lines: list[str], i: int) -> int: | ||
| """The index after the block indented under a title at line `i`, or i + 1 if none.""" | ||
| if not _TITLE.fullmatch(lines[i].strip()): | ||
| return i + 1 | ||
| title_indent = _indent(lines[i]) | ||
| end = i + 1 | ||
| while end < len(lines) and (not lines[end].strip() or _indent(lines[end]) > title_indent): | ||
| end += 1 | ||
| while end > i + 1 and not lines[end - 1].strip(): | ||
| end -= 1 | ||
| return end | ||
|
|
||
|
|
||
| def _is_code(title: str, block: list[str]) -> bool: | ||
| """Whether the block under `title` is code rather than items, a doctest or prose.""" | ||
| body = [line.strip() for line in block if line.strip()] | ||
| if not body or title.lower() in _STRUCTURED: | ||
| return False | ||
| if any(line.startswith("```") for line in body): | ||
| return False | ||
| # Doctests too: griffe's own doctest parsing stops at a bare ">>>" and leaves the rest as text. | ||
| if _is_doctest(body): | ||
| return True | ||
| if all(line.startswith(("- ", "* ")) for line in body): | ||
| return False | ||
| if any(word in title.lower() for word in _EXAMPLE_WORDS): | ||
| return True | ||
| return _language(_dedent(block)) != "text" | ||
|
|
||
|
|
||
| def _fenced(block: list[str]) -> list[str]: | ||
| """The block as a fenced code block at its own indentation.""" | ||
| body = _dedent(block) | ||
| pad = " " * min(_indent(line) for line in block if line.strip()) | ||
| fence = [f"{pad}```{_language(body)}"] | ||
| fence += [f"{pad}{line}" if line else "" for line in body] | ||
| return [*fence, f"{pad}```"] | ||
|
|
||
|
|
||
| def _indent(line: str) -> int: | ||
| """The number of leading spaces.""" | ||
| return len(line) - len(line.lstrip()) | ||
|
|
||
|
|
||
| def _dedent(block: list[str]) -> list[str]: | ||
| """The block's lines without their common indentation.""" | ||
| indent = min(_indent(line) for line in block if line.strip()) | ||
| return [line[indent:] for line in block] | ||
|
|
||
|
|
||
| def _is_doctest(lines: list[str]) -> bool: | ||
| """Whether the block is an interactive session: it opens with a >>> prompt.""" | ||
| first = next((line.strip() for line in lines if line.strip()), "") | ||
| return first.startswith(">>>") | ||
|
|
||
|
|
||
| def _language(body: list[str]) -> str: | ||
| """pycon for a doctest, python if it parses, yaml if every line looks like YAML, else text. | ||
|
|
||
| `key: value` lines also parse as Python annotations; a block of nothing else is YAML. | ||
| """ | ||
| if _is_doctest(body): | ||
| return "pycon" | ||
| yaml_shaped = all(_YAML_LINE.fullmatch(line) for line in body if line.strip()) | ||
| try: | ||
| tree = ast.parse("\n".join(body)) | ||
| except SyntaxError: | ||
| return "yaml" if yaml_shaped else "text" | ||
| only_annotations = bool(tree.body) and all(isinstance(s, ast.AnnAssign) for s in tree.body) | ||
| return "yaml" if yaml_shaped and only_annotations else "python" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| {#- | ||
| The theme's site_nav block (zensical 0.1.2 base.html), with the docs search placed in the | ||
| primary sidebar above its scroll container, so it stays put while the tree scrolls. | ||
| Re-check against the theme's base.html when upgrading zensical. | ||
| -#} | ||
| {% extends "base.html" %} | ||
|
|
||
| {% block site_nav %} | ||
| {% if nav %} | ||
| {% if page.meta and page.meta.hide %} | ||
| {% set hidden = "hidden" if "navigation" in page.meta.hide %} | ||
| {% endif %} | ||
| <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" {{ hidden }}> | ||
| <div class="lw-tree-search"> | ||
| {% include "partials/search.html" %} | ||
| </div> | ||
| <div class="md-sidebar__scrollwrap"> | ||
| <div class="md-sidebar__inner"> | ||
| {% include "partials/nav.html" %} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endif %} | ||
| {% if "toc.integrate" not in features %} | ||
| {% if page.meta and page.meta.hide %} | ||
| {% set hidden = "hidden" if "toc" in page.meta.hide %} | ||
| {% endif %} | ||
| <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" {{ hidden }}> | ||
| <div class="md-sidebar__scrollwrap"> | ||
| {% if config.theme.variant != "classic" %} | ||
| {% set toc = page.toc %} | ||
| {% set first = toc | first %} | ||
| {% if first and first.level == 1 %} | ||
| {% set toc = first.children %} | ||
| {% endif %} | ||
| {% if toc %} | ||
| <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc"> | ||
| <div class="md-sidebar-button__wrapper"> | ||
| <label class="md-sidebar-button" for="__toc"></label> | ||
| </div> | ||
| {% endif %} | ||
| {% endif %} | ||
| <div class="md-sidebar__inner"> | ||
| {% include "partials/toc.html" %} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endif %} | ||
| {% endblock %} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore a visible search trigger on phones.
On a fresh phone load, the stock modern stylesheet hides
.md-searchat narrow widths, even when the drawer is open. The header override also removes the stock trigger for__search. Restore that trigger in the docs bar so touch users can open search without changing the desktop layout. (raw.githubusercontent.com)Keep the search control outside the instant-navigation container.
Instant navigation swaps
[data-md-component=container], and the primary sidebar that holds the search partial sits inside that container. Search is mounted once at startup, so its click handler stays bound to the removed element. The replacement control has no click handler, so it may not open search until a full reload.Place the search control in a region that navigation does not replace. Alternatively, mount search again on each navigation, which also requires removing the previous host.