Generate static files as part of the build process
This commit is contained in:
parent
29e03c2732
commit
e7615c4947
|
@ -1,14 +1,23 @@
|
|||
source $stdenv/setup
|
||||
|
||||
# Set up Ruby to use UTF-8
|
||||
export RUBYOPT="-KU -E utf-8:utf-8"
|
||||
|
||||
# Copy files to a mutable directory.
|
||||
cp -r $src/* .
|
||||
|
||||
# Hugo can't set baseUrl via CLI for multi-lingual hosts.
|
||||
# We have to manually edit the configuration.
|
||||
patchPhase
|
||||
# We'll generate some static files so make static writable
|
||||
chmod -R u+w .
|
||||
|
||||
# Build site with Hugo
|
||||
hugo $extraFlags
|
||||
hugo $hugoFlags --config=config.toml,config-gen.toml
|
||||
|
||||
# Create generated files
|
||||
# Can't do submodules because nix flake inputs get their .git deleted
|
||||
ruby ./analyze.rb > static/graph/graph.gen.js # Graph files
|
||||
stork build --input public/index.toml --output static/index.st # Search index
|
||||
|
||||
# Static folder changed, re-run Hugo
|
||||
hugo $hugoFlags --config=config.toml,config-gen.toml
|
||||
|
||||
# Output result
|
||||
mkdir $out
|
||||
|
|
28
flake.lock
28
flake.lock
|
@ -3,11 +3,11 @@
|
|||
"blog-source": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1672436100,
|
||||
"narHash": "sha256-shDvdyMXeTs2VVfIOOIQpF6eAe/5nAS8vZL2QA7ryIA=",
|
||||
"lastModified": 1672443445,
|
||||
"narHash": "sha256-s7woTyMkyrtudu20bUcbyF5HXFXGa4NdM7H9id4mTVw=",
|
||||
"ref": "master",
|
||||
"rev": "e7cb818f055d91faabfe3eb4919b6508b29d28c6",
|
||||
"revCount": 609,
|
||||
"rev": "0dfb964e99d20a8d630dacc7670e77bcbea8d43c",
|
||||
"revCount": 610,
|
||||
"submodules": true,
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Web-Projects/blog-static.git"
|
||||
|
@ -18,25 +18,6 @@
|
|||
"url": "https://dev.danilafe.com/Web-Projects/blog-static.git"
|
||||
}
|
||||
},
|
||||
"blog-source-localized": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1599463261,
|
||||
"narHash": "sha256-n6e4uRiOsWuOL7DSzbuP9X8cZNLnKOD/2/eOT0aB+Io=",
|
||||
"ref": "localization",
|
||||
"rev": "0b5748cc5a19b5d1d78bfcfa58d4027cc10524dd",
|
||||
"revCount": 367,
|
||||
"submodules": true,
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Web-Projects/blog-static.git"
|
||||
},
|
||||
"original": {
|
||||
"ref": "localization",
|
||||
"submodules": true,
|
||||
"type": "git",
|
||||
"url": "https://dev.danilafe.com/Web-Projects/blog-static.git"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1648297722,
|
||||
|
@ -169,7 +150,6 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"blog-source": "blog-source",
|
||||
"blog-source-localized": "blog-source-localized",
|
||||
"flake-utils": "flake-utils",
|
||||
"katex-html": "katex-html",
|
||||
"nixpkgs": "nixpkgs_3"
|
||||
|
|
11
flake.nix
11
flake.nix
|
@ -9,19 +9,12 @@
|
|||
type = "git";
|
||||
submodules = true;
|
||||
};
|
||||
blog-source-localized = {
|
||||
flake = false;
|
||||
url = "https://dev.danilafe.com/Web-Projects/blog-static.git";
|
||||
ref = "localization";
|
||||
type = "git";
|
||||
submodules = true;
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, blog-source, blog-source-localized, nixpkgs, flake-utils, katex-html }:
|
||||
outputs = { self, blog-source, nixpkgs, flake-utils, katex-html }:
|
||||
let
|
||||
buildersFor = system: import ./lib.nix {
|
||||
inherit blog-source blog-source-localized;
|
||||
inherit blog-source;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
katex-html = katex-html.defaultPackage.${system};
|
||||
};
|
||||
|
|
34
lib.nix
34
lib.nix
|
@ -1,23 +1,24 @@
|
|||
{ blog-source, blog-source-localized, pkgs, katex-html }:
|
||||
{ blog-source, pkgs, katex-html }:
|
||||
|
||||
with pkgs;
|
||||
with lib;
|
||||
|
||||
let
|
||||
protocol = ssl: if ssl then "https://" else "http://";
|
||||
website = settings: stdenv.mkDerivation {
|
||||
inherit (settings) src ssl host;
|
||||
name = "blog-static";
|
||||
version = settings.src.rev;
|
||||
postPatch = with settings.replaceUrl; ''
|
||||
substituteInPlace config.toml --replace ${from} ${to}
|
||||
'';
|
||||
version = settings.src.rev or "dirty";
|
||||
publicPath = settings.path;
|
||||
extraFlags = (if settings.drafts then " -D " else "") + settings.extraFlags;
|
||||
hugoFlags = concatStringsSep " " (
|
||||
optionals settings.drafts (singleton "-D") ++
|
||||
[ "--baseURL=${protocol settings.ssl + settings.host}" ]
|
||||
);
|
||||
builder = ./build/builder.sh;
|
||||
buildInputs = [
|
||||
hugo katex-html
|
||||
hugo ruby stork katex-html
|
||||
];
|
||||
};
|
||||
wrapHost = ssl: host: (if ssl then "https" else "http") + "://${host}";
|
||||
in
|
||||
{
|
||||
english = settings: website {
|
||||
|
@ -26,22 +27,5 @@ in
|
|||
drafts = settings.drafts or false;
|
||||
src = blog-source;
|
||||
path = ".";
|
||||
extraFlags = "--config=config.toml,config-gen.toml";
|
||||
replaceUrl = {
|
||||
from = "https://danilafe.com";
|
||||
to = wrapHost (settings.ssl or false) settings.host;
|
||||
};
|
||||
};
|
||||
russian = settings: website {
|
||||
inherit (settings) host;
|
||||
ssl = settings.ssl or false;
|
||||
drafts = settings.drafts or false;
|
||||
src = blog-source-localized;
|
||||
path = "ru";
|
||||
extraFlags = "";
|
||||
replaceUrl = {
|
||||
from = "https://ru.danilafe.com";
|
||||
to = wrapHost (settings.ssl or false) settings.host;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user