Skip to content

Commit d2d33ef

Browse files
committed
Generate categorical pages
1 parent 6126504 commit d2d33ef

5 files changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ jobs:
3333
3434
- name: Build docs
3535
run: |
36-
mkdocs build --strict
36+
make build
3737
3838
# TODO: Internal link check

.readthedocs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ build:
66
os: ubuntu-24.04
77
tools:
88
python: "3"
9+
jobs:
10+
pre_build:
11+
- make pre-build
912

1013
mkdocs:
1114
configuration: mkdocs.yml

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
pre-build:
3+
python ./plugins/create_category_pages.py
4+
5+
build: pre-build
6+
mkdocs build --strict
7+
8+
serve: pre-build
9+
mkdocs serve
10+
11+
.PHONY: clean
12+
clean:
13+
rm -f docs/categories/*
14+
rm -rf site/*

docs/categories/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*

plugins/create_category_pages.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
from pathlib import Path
3+
import re
4+
import yaml
5+
6+
7+
def _slugify(s: str):
8+
return re.sub(r"\W", "-", s.lower())
9+
10+
ROOT = Path(__file__).parent / ".."
11+
12+
TEMPLATE = """
13+
# %CATEGORY%
14+
15+
{{ read_yaml("uktre-glossary.yaml", record_path="glossary", category="%CATEGORY%") }}
16+
"""
17+
18+
with open(ROOT / "assets" / "uktre-glossary.yaml") as f:
19+
data = yaml.safe_load(f)
20+
categories = set(t for term in data["glossary"] for t in term["tags"])
21+
22+
# Check categories don't have inconsistent names
23+
slugs = {}
24+
for category in categories:
25+
slug = _slugify(category)
26+
if slug in slugs:
27+
raise ValueError(f"Category has inconsistent naming: '{slugs[slug]}' '{category}'")
28+
slugs[slug] = category
29+
30+
for slug, category in sorted(slugs.items()):
31+
print(f"{category:<40} {slug}")
32+
with open(ROOT / "docs" / "categories" / f"{slug}.md", "w") as f:
33+
f.write(TEMPLATE.replace("%CATEGORY%", category))

0 commit comments

Comments
 (0)