mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 06:21:30 +03:00
reference-docs: fix option rendering issue
remove tree-style preprocessing since it is not needed anymore
This commit is contained in:
parent
4c89b02025
commit
4e9fd61a12
@ -41,25 +41,6 @@ def sort_options(item: Tuple[str, Dict], module_name: str) -> int:
|
|||||||
return ord(name[0])
|
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(
|
def on_page_markdown(
|
||||||
markdown: str, page: Page, config: MkDocsConfig, files: Files
|
markdown: str, page: Page, config: MkDocsConfig, files: Files
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
@ -84,7 +65,8 @@ def on_page_markdown(
|
|||||||
log.error(f"{options_path} does not exist")
|
log.error(f"{options_path} does not exist")
|
||||||
return None
|
return None
|
||||||
with open(options_path, "r") as f:
|
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)
|
reference = env.get_template("reference_options.html").render(options=options)
|
||||||
|
|
||||||
return "\n\n".join([header, markdown, reference])
|
return "\n\n".join([header, markdown, reference])
|
||||||
|
@ -148,7 +148,7 @@
|
|||||||
if [ ! -d src/reference ]; then
|
if [ ! -d src/reference ]; then
|
||||||
echo "linking .#reference to src/reference, you need to update this manually\
|
echo "linking .#reference to src/reference, you need to update this manually\
|
||||||
and remove it before a production build"
|
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
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user