2024-04-16 13:05:35 +00:00
|
|
|
{ self, ... }:
|
2024-01-17 07:13:09 +00:00
|
|
|
{
|
2024-04-16 13:05:35 +00:00
|
|
|
perSystem =
|
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
self',
|
|
|
|
inputs',
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
build =
|
|
|
|
baseUrl:
|
|
|
|
pkgs.runCommand "website" { buildInputs = [ pkgs.zola ]; } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cp -r ${self}/* .
|
|
|
|
chmod -R u+w .
|
2024-01-17 07:13:09 +00:00
|
|
|
|
2024-04-16 13:05:35 +00:00
|
|
|
substituteInPlace config.toml --replace \
|
|
|
|
'base_url = "https://clan.lol"' \
|
|
|
|
'base_url = "${baseUrl}"' \
|
2024-01-17 07:13:09 +00:00
|
|
|
|
2024-04-16 13:05:35 +00:00
|
|
|
# generates a zola compatible .md from a clan-core/docs/**/*.md
|
|
|
|
generatePage() {
|
|
|
|
local sourceFile="$1"
|
|
|
|
local targetFile="$2"
|
2024-01-17 07:13:09 +00:00
|
|
|
|
2024-04-16 13:05:35 +00:00
|
|
|
# generate title by reading first non-empty line of $file and stripping all '#' symbols
|
|
|
|
title=$(sed -n '/./{p;q}' "$sourceFile" | sed 's/#*//g')
|
|
|
|
echo "generating page from clan-core: $title"
|
2024-01-17 07:13:09 +00:00
|
|
|
|
2024-04-16 13:05:35 +00:00
|
|
|
# generate header with title, template, weight to make zola happy
|
|
|
|
echo -e "+++\ntitle = \"$title\"\ntemplate = \"docs/page.html\"\nweight = 0\n+++" > "$targetFile"
|
2024-01-17 07:13:09 +00:00
|
|
|
|
2024-04-16 13:05:35 +00:00
|
|
|
# append everything from the file but remove header line starting with '#' and all preceding non-empty lines
|
|
|
|
tail -n +2 "$sourceFile" >> "$targetFile"
|
|
|
|
}
|
2024-01-17 07:13:09 +00:00
|
|
|
|
2024-04-16 13:05:35 +00:00
|
|
|
zola build
|
|
|
|
cp -r public/* public/.* $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
packages.default = self'.packages.website;
|
|
|
|
packages.website = build "https://clan.lol";
|
|
|
|
packages.website-localhost = build "http://localhost:1111";
|
|
|
|
packages.serve = pkgs.writeShellScriptBin "serve-local" ''
|
|
|
|
echo "serving: ${self'.packages.website-localhost}"
|
|
|
|
${pkgs.python3}/bin/python -m http.server 1111 \
|
|
|
|
-d ${self'.packages.website-localhost}
|
|
|
|
'';
|
|
|
|
};
|
2024-01-17 07:13:09 +00:00
|
|
|
}
|