clan-core/docs/flake-module/zola-pages.nix
Valentin Gagarin 0681f6bf7c
All checks were successful
checks / checks-impure (pull_request) Successful in 1m53s
checks / checks (pull_request) Successful in 3m49s
checks / check-links (pull_request) Successful in 14s
docs: don't set page weight
since currently the web site simply dumps these pages, this makes it
impossible to control the item order
2024-04-05 21:52:56 +02:00

89 lines
2.4 KiB
Nix

{
perSystem =
{
lib,
pkgs,
self',
...
}:
let
getMdPages =
prefix:
let
mdDocs' = lib.filterAttrs (name: _: lib.hasPrefix prefix name) self'.packages;
mdDocs = lib.mapAttrs' (name: pkg: lib.nameValuePair (lib.removePrefix prefix name) pkg) mdDocs';
in
if mdDocs != { } then
mdDocs
else
throw ''
Error: no markdown files found in clan-core.packages' with prefix "${prefix}"
'';
makeZolaIndexMd =
title: weight:
pkgs.writeText "_index.md" ''
+++
title = "${title}"
template = "docs/section.html"
weight = ${toString weight}
sort_by = "title"
draft = false
+++
'';
makeZolaPages =
{
sectionTitle,
files,
makeIntro ? _name: "",
weight ? 9999,
}:
pkgs.runCommand "zola-pages-clan-core" { } ''
mkdir $out
# create new section via _index.md
cp ${makeZolaIndexMd sectionTitle weight} $out/_index.md
# generate zola compatible md files for each nixos options md
${lib.concatStringsSep "\n" (
lib.flip lib.mapAttrsToList files (
name: md: ''
# generate header for zola with title, template, weight
title="${name}"
echo -e "+++\ntitle = \"$title\"\ntemplate = \"docs/page.html\"\n+++" > "$out/${name}.md"
cat <<EOF >> "$out/${name}.md"
${makeIntro name}
EOF
# append everything from the nixpkgs generated md file
cat "${md}" >> "$out/${name}.md"
''
)
)}
'';
in
{
packages.docs-zola-pages-core = makeZolaPages {
sectionTitle = "cLAN Core Reference";
files = getMdPages "docs-md-core-";
weight = 20;
};
packages.docs-zola-pages-modules = makeZolaPages {
sectionTitle = "cLAN Modules Reference";
files = getMdPages "docs-md-module-";
weight = 25;
makeIntro = name: ''
To use this module, import it like this:
\`\`\`nix
{config, lib, inputs, ...}: {
imports = [inputs.clan-core.clanModules.${name}];
# ...
}
\`\`\`
'';
};
};
}