From 3dcb95fbd9384f57d2c8a689adabe6aaf9a82c04 Mon Sep 17 00:00:00 2001 From: Michael Walker Date: Tue, 10 Dec 2024 18:21:43 +0000 Subject: [PATCH] Add "Host Templates" section to docs These will live in `hosts/_templates` --- docs/.gitignore | 1 + docs/src/SUMMARY.md | 1 + scripts/documentation.sh | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/.gitignore b/docs/.gitignore index 36948ce0..3ceb12b9 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -3,6 +3,7 @@ book # generated by the build script src/README.md src/hosts.md +src/host-templates.md src/modules.md src/options.md src/packages.md diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 6ebc5b33..22222de2 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -5,6 +5,7 @@ # Reference - [Hosts](./hosts.md) +- [Host Templates](./host-templates.md) - [Modules](./modules.md) - [Options](./options.md) diff --git a/scripts/documentation.sh b/scripts/documentation.sh index ec338fdc..766c37bd 100644 --- a/scripts/documentation.sh +++ b/scripts/documentation.sh @@ -12,10 +12,13 @@ import os print("# Hosts") print("") -hosts = sorted([name for name in os.listdir("hosts") if name not in [".", ".."]]) +hosts = sorted([name for name in os.listdir("hosts")]) for host in hosts: source_file = f"hosts/{host}/configuration.nix" + if not os.path.isfile(source_file): + continue + print(f"## {host}") has_doc = False @@ -32,6 +35,35 @@ for host in hosts: print("") EOF +python3 - <<'EOF' > docs/src/host-templates.md +import os + +print("# Host Templates") +print("") + +templates = sorted([name for name in os.listdir("hosts/_templates")]) +for template in templates: + source_file = f"hosts/_templates/{template}" + + if not os.path.isfile(source_file): + continue + + print(f"## {template.replace('.nix','')}") + + has_doc = False + with open(source_file, "r") as f: + for line in f: + if line.startswith("#"): + has_doc = True + print(line[1:].strip()) + else: + break + if not has_doc: + print("This template has no description.") + print(f"\n**Declared in:** [{source_file}](https://github.com/barrucadu/nixfiles/blob/master/{source_file})") + print("") +EOF + python3 - <<'EOF' > docs/src/modules.md import json import os