gr-base/nix/website.nix
2025-08-27 21:11:14 +07:00

78 lines
2.1 KiB
Nix

{ pkgs, root }:
pkgs.stdenv.mkDerivation {
name = "grimu-r-website";
src = pkgs.lib.cleanSourceWith {
src = root;
filter = path: type:
let
baseName = baseNameOf path;
relativePath = pkgs.lib.removePrefix (toString root + "/") (toString path);
in
baseName == "README.org" ||
relativePath == "website" ||
pkgs.lib.hasPrefix "website/" relativePath;
};
buildInputs = [ pkgs.pandoc ];
buildPhase = ''
cp $src/website/pandoc-template.html ./
mkdir -p ./html/doc
cp $src/website/favicon.ico ./html/
cp $src/website/llms.txt ./html/
if [ -d "$src/website/doc" ]; then
echo '<nav class="sidebar"><ul>' > docs-nav.html
for file in $(find $src/website/doc -name "*.org" -type f | sort); do
basename=$(basename "$file" .org)
title=$(grep -m1 -i "^#+TITLE:" "$file" | sed 's/^#+TITLE:[[:space:]]*//I' || echo "$basename")
echo "<li><a href=\"$basename.html\">$title</a></li>" >> docs-nav.html
done
echo '</ul></nav>' >> docs-nav.html
fi
if [ -d "$src/website/doc" ]; then
for file in $src/website/doc/*.org; do
basename=$(basename "$file" .org)
pandoc \
--template=./pandoc-template.html \
--include-before-body=./docs-nav.html \
--shift-heading-level-by=1 \
--section-divs \
-M document-css=false \
"$file" \
-o "./html/doc/$basename.html"
done
fi
pandoc \
--template=./pandoc-template.html \
--shift-heading-level-by=1 \
--section-divs \
-M document-css=false \
$src/README.org \
-o html/index.html
pandoc \
--template=./pandoc-template.html \
--shift-heading-level-by=1 \
--section-divs \
-M document-css=false \
$src/website/pitch.org \
-o html/pitch.html
'';
installPhase = ''
mkdir -p $out/html
mkdir -p $out/bin
cp -r ./html $out/
cat > $out/bin/grimu-r-website <<EOF
#!/usr/bin/env bash
${pkgs.python3}/bin/python3 -m http.server --directory "$out/html"
EOF
chmod +x $out/bin/grimu-r-website
'';
}