diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e23cab --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +* + +!site/ + +!.gitignore +!flake.lock + +!*.nix +!*.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..74ed9d0 --- /dev/null +++ b/build.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -e # Fail fast. + +rm -rf _site + +# Creates all dirs needed. +for dir in $(find site -type d); do + mkdir -p "_$dir" +done + +if [[ "$HTMNIX_LOCAL" == 1 ]]; then + FLAKE_REF=. +else + FLAKE_REF=github:RGBCube/HTMNIX +fi + +for file in $(find site -type f); do + if [[ ! "$file" =~ ^_ ]]; then + if [[ "$file" =~ .nix$ ]]; then + echo "Processing file $file to _${file%.nix}.html..." + TARGET_FILE="$file" nix eval "$FLAKE_REF#result" --apply toString --raw > "_${file%.nix}.html" + echo "Done!" + else + echo "Copying file $file to _$file..." + cp "$file" "_$file" + echo "Done!" + fi + fi +done + +echo "All done!" diff --git a/flake.nix b/flake.nix index e1ddeb2..57c06dd 100644 --- a/flake.nix +++ b/flake.nix @@ -74,6 +74,9 @@ }; }; - result = builtins.scopedImport { inherit (self) raw __findFile; } ./html.nix; + result = let + targetFile = builtins.getEnv "TARGET_FILE"; + targetFile' = if targetFile != "" then targetFile else "site/index.nix"; + in builtins.scopedImport { inherit (self) raw __findFile; } ./${targetFile'}; }; } diff --git a/html.nix b/site/index.nix similarity index 100% rename from html.nix rename to site/index.nix