From 6ce9145fa101e623c61f009c9cf5bb75a8a4a108 Mon Sep 17 00:00:00 2001 From: Yuriy Andamasov Date: Wed, 6 May 2026 23:02:55 +0300 Subject: docs(conf.py): drop dirhtml from llms.txt builder list, use StrictUndefined Two follow-up Copilot findings on the curated llms.txt render: 1. Drop `dirhtml` from the builder allow-list. The template hard-codes `.html` URLs (`quick-start.html`), which don't exist under `dirhtml` output (`quick-start/index.html`). Production publishes via the `html`/`readthedocs` builders, so `make dirhtml` would only emit a misleading file. Cleaner to skip than to branch URL generation on builder type for a path we don't actually ship. 2. Use a Jinja `Environment` with `StrictUndefined` instead of a bare `Template`. A typo in `llms.txt.j2` (e.g. `{{ relase }}`) now raises at build time instead of silently rendering as an empty string and shipping a half-blank `llms.txt`. Also set `keep_trailing_newline` so the rendered file's terminating newline is preserved. Addresses Copilot review feedback on PR #1874. \xf0\x9f\xa4\x96 Generated by [robots](https://vyos.io) --- docs/conf.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/conf.py b/docs/conf.py index e9b28b71..72c4595a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -220,15 +220,24 @@ def _prefer_webp(app): def _write_llms_txt(app, exception): + # Skip dirhtml: the curated template encodes `.html` URLs (e.g. + # `quick-start.html`), which don't exist under `dirhtml` output + # (`quick-start/index.html`). Production publishes via the html / + # readthedocs builders, so dirhtml output would just be misleading. if exception is not None or app.builder.name not in ( - 'html', 'dirhtml', 'readthedocs'): + 'html', 'readthedocs'): return from pathlib import Path - from jinja2 import Template + from jinja2 import Environment, StrictUndefined tpl_path = Path(app.srcdir) / '_templates' / 'llms.txt.j2' out_path = Path(app.outdir) / 'llms.txt' baseurl = (app.config.html_baseurl or '').rstrip('/') + '/' - rendered = Template(tpl_path.read_text(encoding='utf-8')).render( + # StrictUndefined: missing template variables raise rather than + # silently render as empty strings, so a typo in llms.txt.j2 fails + # the build instead of shipping a half-blank llms.txt. + env = Environment(undefined=StrictUndefined, keep_trailing_newline=True) + template = env.from_string(tpl_path.read_text(encoding='utf-8')) + rendered = template.render( baseurl=baseurl, release=app.config.release, ) -- cgit v1.2.3