From 5c234ac64353e472c67fbfde52ef54bb08cdc214 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 9 Jul 2025 17:24:20 +0200 Subject: [PATCH] Docs: fix rendering clan source code url --- docs/nix/render_options/__init__.py | 13 +++++-------- lib/docs.nix | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docs/nix/render_options/__init__.py b/docs/nix/render_options/__init__.py index fd8bf49dd..c62e34d3c 100644 --- a/docs/nix/render_options/__init__.py +++ b/docs/nix/render_options/__init__.py @@ -62,14 +62,11 @@ def sanitize(text: str) -> str: return text.replace(">", "\\>") -def replace_store_path(text: str) -> tuple[str, str]: +def replace_git_url(text: str) -> tuple[str, str]: res = text - if text.startswith("/nix/store/"): - res = "https://git.clan.lol/clan/clan-core/src/branch/main/" + str( - Path(*Path(text).parts[4:]) - ) - # name = Path(res).name - name = str(Path(*Path(text).parts[4:])) + name = Path(res).name + if text.startswith("https://git.clan.lol/clan/clan-core/src/branch/main/"): + name = str(Path(*Path(text).parts[7:])) return (res, name) @@ -159,7 +156,7 @@ def render_option( decls = option.get("declarations", []) if decls: - source_path, name = replace_store_path(decls[0]) + source_path, name = replace_git_url(decls[0]) name = name.split(",")[0] source_path = source_path.split(",")[0] diff --git a/lib/docs.nix b/lib/docs.nix index 0e6cca95e..2e2c0f274 100644 --- a/lib/docs.nix +++ b/lib/docs.nix @@ -1,21 +1,25 @@ { lib, ... }: -{ +rec { + prefix = "https://git.clan.lol/clan/clan-core/src/branch/main/"; # Strip store paths from option declarations to make docs more stable # This prevents documentation from rebuilding when store paths change # but the actual content remains the same - stripStorePathsFromDeclarations = opt: - opt // { - declarations = map (decl: + stripStorePathsFromDeclarations = + opt: + opt + // { + declarations = map ( + decl: if lib.isString decl && lib.hasPrefix "/nix/store/" decl then let parts = lib.splitString "/" decl; in - if builtins.length parts > 4 then - "/" + lib.concatStringsSep "/" (lib.drop 4 parts) - else - decl + if builtins.length parts > 4 then + (prefix + "/" + lib.concatStringsSep "/" (lib.drop 4 parts)) + else + decl else decl ) opt.declarations; }; -} \ No newline at end of file +}