Skip to content

Commit 569b6d7

Browse files
committed
feat: build YAML table of contents for examples
1 parent a943429 commit 569b6d7

File tree

5 files changed

+2091
-1434
lines changed

5 files changed

+2091
-1434
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ examples-force:
3535
touch ${EXAMPLES_SRC}
3636
make examples
3737

38+
## examples-toc: generate YAML table of contents for examples
39+
examples-toc:
40+
@python bin/build_example_toc.py ${EXAMPLE_SRC}
41+
3842
## format: reformat code
3943
format:
4044
${RUN} ruff format ${CODE_DIRS}

bin/build_example_toc.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from collections import defaultdict
2+
from pathlib import Path
3+
import sys
4+
import yaml
5+
6+
7+
SKIPS = {"getting-started.md"}
8+
9+
10+
def main():
11+
"""Main driver."""
12+
sources = [Path(a) for a in sys.argv[1:]]
13+
sources = [src for src in sources if str(src.name) not in SKIPS]
14+
15+
sections = defaultdict(list)
16+
for src in sources:
17+
try:
18+
content = src.read_text()
19+
header = content.split("---")[1].strip()
20+
data = yaml.safe_load(header)
21+
data = data["jupyter"]["plotly"]
22+
display = data["display_as"]
23+
order = float(data["order"])
24+
sections[display].append((order, data, src.name))
25+
except Exception as exc:
26+
print(f"failed to load from {src}: {exc}", file=sys.stderr)
27+
28+
for key, values in sorted(sections.items()):
29+
values.sort(key=lambda x: float(x[0]))
30+
print(f"- {key}")
31+
for (order, data, src) in values:
32+
print(f' - {src}: "{data["name"]}"')
33+
34+
35+
if __name__ == "__main__":
36+
main()

bin/check-all-md.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ dev_build = [
5656
"mkdocs-material",
5757
"mkdocstrings[python]",
5858
"mkdocs-gen-files",
59-
"mkdocs-literate-nav"
59+
"mkdocs-literate-nav",
60+
"pyyaml"
6061
]
6162
dev_optional = [
6263
"plotly[dev_build]",

0 commit comments

Comments
 (0)