Skip to content

Commit

Permalink
reference-docs: fix option rendering issue
Browse files Browse the repository at this point in the history
remove tree-style preprocessing since it is not needed anymore
  • Loading branch information
DavHau authored and mergify[bot] committed Jul 18, 2024
1 parent 4c89b02 commit 4e9fd61
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
22 changes: 2 additions & 20 deletions docs/hooks/render_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,6 @@ def sort_options(item: Tuple[str, Dict], module_name: str) -> int:
return ord(name[0])


def preprocess_options(options, module_name):
tree = dict()
for name, option in options.items():
if name.startswith("_module"):
continue
cursor = tree
parts = name.split(".")
for index, part in enumerate(parts):
if part not in cursor:
if index + 1 == len(parts):
cursor[part] = dict(**option, children={})
else:
cursor[part] = dict(children=dict())
cursor = cursor[part]["children"]
else:
cursor = cursor[part]["children"]
return OrderedDict(sorted(tree.items(), key=lambda i: sort_options(i, module_name)))


def on_page_markdown(
markdown: str, page: Page, config: MkDocsConfig, files: Files
) -> str | None:
Expand All @@ -84,7 +65,8 @@ def on_page_markdown(
log.error(f"{options_path} does not exist")
return None
with open(options_path, "r") as f:
options = preprocess_options(json.load(f), module_name)
options = json.load(f)
del options["_module.args"]
reference = env.get_template("reference_options.html").render(options=options)

return "\n\n".join([header, markdown, reference])
Expand Down
2 changes: 1 addition & 1 deletion modules/flake-parts/reference-website/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
if [ ! -d src/reference ]; then
echo "linking .#reference to src/reference, you need to update this manually\
and remove it before a production build"
ln -sfT $(nix build ..#reference --no-link --print-out-paths) src/reference
ln -sfT $(nix build .#optionsReference --no-link --print-out-paths) src/reference
fi
'';
};
Expand Down

0 comments on commit 4e9fd61

Please sign in to comment.