diff options
author | Naïm Favier <n@monade.li> | 2023-01-02 14:09:29 +0100 |
---|---|---|
committer | Naïm Favier <n@monade.li> | 2023-01-03 14:03:35 +0100 |
commit | f61e538c432a87eb0601d5da910abda131459fdb (patch) | |
tree | 72f83317e4bd4b0a555a17f913c03c16e017842c | |
parent | a8d4cf149cda4f82145291cc9a6819a9baa3951e (diff) |
nixos/make-options-doc: link manpages
Add links to manpages without a link using the mapping defined in
`doc/manpage-urls.json`, as is already done for the nixpkgs and NixOS
manuals.
-rw-r--r-- | nixos/lib/make-options-doc/default.nix | 2 | ||||
-rw-r--r-- | nixos/lib/make-options-doc/mergeJSON.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/nixos/lib/make-options-doc/default.nix b/nixos/lib/make-options-doc/default.nix index a3436caad8f9..f2bcbba69aec 100644 --- a/nixos/lib/make-options-doc/default.nix +++ b/nixos/lib/make-options-doc/default.nix @@ -130,6 +130,8 @@ in rec { if baseOptionsJSON == null then builtins.toFile "base.json" "{}" else baseOptionsJSON; + + MANPAGE_URLS = pkgs.path + "/doc/manpage-urls.json"; } '' # Export list of options in different format. diff --git a/nixos/lib/make-options-doc/mergeJSON.py b/nixos/lib/make-options-doc/mergeJSON.py index 750cd24fc653..070f2d6025a2 100644 --- a/nixos/lib/make-options-doc/mergeJSON.py +++ b/nixos/lib/make-options-doc/mergeJSON.py @@ -1,5 +1,6 @@ import collections import json +import os import sys from typing import Any, Dict, List @@ -46,6 +47,8 @@ def unpivot(options: Dict[Key, Option]) -> Dict[str, JSON]: result[opt.name] = opt.value return result +manpage_urls = json.load(open(os.getenv('MANPAGE_URLS'))) + admonitions = { '.warning': 'warning', '.important': 'important', @@ -119,9 +122,14 @@ class Renderer(mistune.renderers.BaseRenderer): def env(self, text): return f"<envar>{escape(text)}</envar>" def manpage(self, page, section): + man = f"{page}({section})" title = f"<refentrytitle>{escape(page)}</refentrytitle>" vol = f"<manvolnum>{escape(section)}</manvolnum>" - return f"<citerefentry>{title}{vol}</citerefentry>" + ref = f"<citerefentry>{title}{vol}</citerefentry>" + if man in manpage_urls: + return self.link(manpage_urls[man], text=ref) + else: + return ref def finalize(self, data): return "".join(data) |