Valentin Gagarin <valentin@gagarin.work> writes:
diff --git a/Documentation/_includes/sitemap.html b/Documentation/_includes/sitemap.html new file mode 100644 index 0000000..723bdb3 --- /dev/null +++ b/Documentation/_includes/sitemap.html @@ -0,0 +1,58 @@ +{% comment %} +SPDX-License-Identifier: GPL-3.0-or-later +SPDX-FileCopyrightText: 2026 Valentin Gagarin <valentin@gagarin.work> + +Render a nested sitemap rooted at a given URL prefix. Hierarchy is +derived from URL structure: a page is a direct child of prefix P iff +its URL starts with P, is not P itself, and contains no further path +segments below P. +{% endcomment %} + +{%- assign default_root = "/" -%} +{% comment %} +`prefix` is the URL of the section to list children of. It must end with "/", +which we assume if it is constructed by a directory and contains an index file. +{% endcomment %} +{%- assign prefix = include.prefix | default: default_root -%} +{%- capture inner -%} + {%- assign candidates = site.html_pages + | where_exp: "p", "p.url contains prefix" + | where_exp: "p", "p.url != prefix" -%} + {%- comment %} + Ordered pages first, ascending. The rest after, in URL order, so output is deterministic. + {%- endcomment %} + {%- assign ordered = candidates | where_exp: "p", "p.nav_order" | sort: "nav_order" -%} + {%- assign unordered = candidates | where_exp: "p", "p.nav_order == nil" | sort: "url" -%} + {%- assign sorted = ordered | concat: unordered -%} + {%- for p in sorted -%} + {%- comment %} + `assign` is page-global. A recursive include below may have overwritten `prefix`. + {%- endcomment %} + {%- assign prefix = include.prefix | default: default_root -%} + {%- assign url_start = p.url | slice: 0, prefix.size -%} + {%- if url_start == prefix -%}
Should be indentation inside this. (Or we could do a continue to avoid rightward drift.) Let me know which you prefer.