2021-11-18 07:21:00 +01:00
|
|
|
let
|
|
|
|
notFound = typ: "<span style=\"color: red;\">Error: No ${typ} passed to the builder</span>";
|
|
|
|
in
|
|
|
|
|
2021-11-18 22:15:20 +01:00
|
|
|
{ lib, stdenv, nix-gitignore, mdbook, python3, writeScript
|
2021-11-18 07:21:00 +01:00
|
|
|
, deploymentOptionsMd ? notFound "deployment options text"
|
|
|
|
, metaOptionsMd ? notFound "meta options text"
|
|
|
|
, colmena ? null
|
2021-11-18 22:15:20 +01:00
|
|
|
|
|
|
|
, version ? null # Full version (default: detected from colmena)
|
|
|
|
, unstable ? null # Whether this build is unstable (default: detected from version)
|
2021-11-18 07:21:00 +01:00
|
|
|
}:
|
|
|
|
|
2021-11-18 22:15:20 +01:00
|
|
|
let
|
|
|
|
versionComp =
|
|
|
|
if version == null then
|
|
|
|
if colmena != null then colmena.version else "unstable"
|
|
|
|
else version;
|
|
|
|
|
|
|
|
unstableComp =
|
|
|
|
if unstable == null then versionComp == "unstable" || lib.hasInfix "-" versionComp
|
|
|
|
else unstable;
|
|
|
|
|
|
|
|
apiVersion = builtins.concatStringsSep "." (lib.take 2 (lib.splitString "." versionComp));
|
|
|
|
|
|
|
|
redirectTemplate = lib.escapeShellArg ''
|
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Redirecting</title>
|
|
|
|
<meta http-equiv="refresh" content="0; URL=https://zhaofengli.github.io/colmena@path@">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Redirecting to <a href="https://zhaofengli.github.io/colmena@path@">https://zhaofengli.github.io/colmena@path@</a>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
'';
|
|
|
|
|
|
|
|
in stdenv.mkDerivation {
|
|
|
|
inherit deploymentOptionsMd metaOptionsMd;
|
2021-11-18 07:21:00 +01:00
|
|
|
|
2021-11-18 22:15:20 +01:00
|
|
|
pname = "colmena-manual" + (if unstableComp then "-unstable" else "");
|
|
|
|
version = versionComp;
|
2021-11-18 07:21:00 +01:00
|
|
|
|
|
|
|
src = nix-gitignore.gitignoreSource [] ./.;
|
|
|
|
|
2021-11-18 22:15:20 +01:00
|
|
|
nativeBuildInputs = [ mdbook python3 ];
|
|
|
|
|
|
|
|
outputs = [ "out" "redirectFarm" ];
|
|
|
|
|
|
|
|
COLMENA_VERSION = versionComp;
|
|
|
|
COLMENA_UNSTABLE = unstableComp;
|
2021-11-18 07:21:00 +01:00
|
|
|
|
|
|
|
patchPhase = ''
|
2021-11-18 22:15:20 +01:00
|
|
|
if [ -z "${toString unstableComp}" ]; then
|
|
|
|
sed "s|@apiVersion@|${apiVersion}|g" book.stable.toml > book.toml
|
2021-11-18 07:21:00 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
2021-11-18 22:15:20 +01:00
|
|
|
if [ -n "${colmena}" ]; then
|
2021-11-18 07:21:00 +01:00
|
|
|
echo "Generating CLI help text"
|
2021-11-18 22:15:20 +01:00
|
|
|
${colmena}/bin/colmena gen-help-markdown >> src/reference/cli.md
|
2021-11-18 07:21:00 +01:00
|
|
|
else
|
|
|
|
echo "Error: No colmena executable passed to the builder" >> src/reference/cli.md
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$deploymentOptionsMd" >> src/reference/deployment.md
|
|
|
|
echo "$metaOptionsMd" >> src/reference/meta.md
|
|
|
|
|
|
|
|
mdbook build -d $out
|
2021-11-18 22:15:20 +01:00
|
|
|
|
|
|
|
# Build the redirect farm
|
|
|
|
# GitHub Pages doesn't play well with directory symlinks. Default
|
|
|
|
# pages (index.html) don't work when a symlink is traversed.
|
|
|
|
|
|
|
|
mkdir -p $redirectFarm
|
|
|
|
|
|
|
|
subdir="/unstable"
|
|
|
|
if [ -z "${toString unstableComp}" ]; then
|
|
|
|
subdir="/${apiVersion}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd $redirectFarm
|
|
|
|
(cd $out; find . -name "*.html") | while read -r page; do
|
|
|
|
strippedPage=''${page#.}
|
|
|
|
target="$subdir$strippedPage"
|
|
|
|
mkdir -p $(dirname $page)
|
|
|
|
echo ${redirectTemplate} | sed "s|@path@|$target|g" > $page
|
|
|
|
done
|
|
|
|
popd
|
2021-11-18 07:21:00 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = "true";
|
|
|
|
}
|