-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a basic reference documentation site
- Loading branch information
Showing
7 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/_site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
book | ||
|
||
# generated by the build script | ||
src/README.md | ||
src/modules.md | ||
src/options.md | ||
mdbook-admonish.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[book] | ||
title = "nixfiles" | ||
authors = ["Michael Walker (barrucadu)"] | ||
description = "My NixOS configuration and assorted other crap, powered by flakes." | ||
language = "en" | ||
multilingual = false | ||
|
||
[build] | ||
create-missing = false | ||
|
||
[output.html] | ||
git-repository-url = "https://github.com/barrucadu/nixfiles" | ||
cname = "nixfiles.docs.barrucadu.co.uk" | ||
|
||
[preprocessor.admonish] | ||
on_failure = "bail" | ||
command = "mdbook-admonish" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Summary | ||
|
||
- [README](./README.md) | ||
|
||
# Reference | ||
|
||
- [Modules](./modules.md) | ||
- [Options](./options.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
set -e | ||
|
||
pushd docs | ||
mdbook-admonish install | ||
popd | ||
|
||
cp README.markdown docs/src/README.md | ||
|
||
python3 - <<'EOF' > docs/src/modules.md | ||
import json | ||
import os | ||
print("# Modules") | ||
print("") | ||
with open(os.getenv("NIXOS_OPTIONS_JSON"), "r") as f: | ||
options = json.load(f) | ||
modules = {} | ||
for key, defn in options.items(): | ||
module_name = defn["declarations"][0].split("/shared/")[1].replace("/options.nix", "") | ||
if module_name == "options.nix": | ||
# this is the top-level `shared` file | ||
module_name = "" | ||
modules.setdefault(module_name, []).append(key) | ||
for module in sorted(modules.keys()): | ||
module_name = "<shared>" if module == "" else module | ||
source_file = f"shared/{module}/default.nix".replace("//", "/") | ||
print(f"## {module_name}") | ||
print(f"\n**Description:**") | ||
has_doc = False | ||
with open(source_file, "r") as f: | ||
for line in f: | ||
if line.startswith("# "): | ||
has_doc = True | ||
print(line[2:].strip()) | ||
else: | ||
break | ||
if not has_doc: | ||
print("This module has no description.") | ||
print("\n**Options:**\n") | ||
for option in modules[module]: | ||
anchor = "".join(c for c in option if c.isalpha() or c == "-") | ||
print(f"- [`{option}`](./options.md#{anchor})") | ||
print(f"\n**Declared in:** [{source_file}](https://github.com/barrucadu/nixfiles/blob/master/{source_file})") | ||
print("") | ||
EOF | ||
|
||
python3 - <<'EOF' > docs/src/options.md | ||
import json | ||
import os | ||
print("# Options") | ||
print("") | ||
with open(os.getenv("NIXOS_OPTIONS_JSON"), "r") as f: | ||
options = json.load(f) | ||
for option in sorted(options.keys()): | ||
defn = options[option] | ||
option_name = option.replace("*", "\\*").replace("<", "<").replace(">", ">") | ||
source_file = "shared/" + defn["declarations"][0].split("/shared/")[1] | ||
print(f"## {option_name}") | ||
print(f"\n**Description:** {defn['description']}") | ||
print(f"\n**Type:** `{defn['type']}`") | ||
if "default" in defn: | ||
print(f"\n**Default:** `{defn['default']['text']}`") | ||
print(f"\n**Declared in:** [{source_file}](https://github.com/barrucadu/nixfiles/blob/master/{source_file})") | ||
print("") | ||
EOF | ||
|
||
mdbook build docs | ||
mv docs/book _site | ||
|
||
chmod -c -R +rX _site | while read -r line; do | ||
echo "::warning title=Invalid file permissions automatically fixed::$line" | ||
done |