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
|
source $stdenv/setup
|
||||||
|
|
||||||
|
# Set up Ruby to use UTF-8
|
||||||
|
export RUBYOPT="-KU -E utf-8:utf-8"
|
||||||
|
|
||||||
# Copy files to a mutable directory.
|
# Copy files to a mutable directory.
|
||||||
cp -r $src/* .
|
cp -r $src/* .
|
||||||
|
# We'll generate some static files so make static writable
|
||||||
# Hugo can't set baseUrl via CLI for multi-lingual hosts.
|
chmod -R u+w .
|
||||||
# We have to manually edit the configuration.
|
|
||||||
patchPhase
|
|
||||||
|
|
||||||
# Build site with Hugo
|
# 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
|
# Output result
|
||||||
mkdir $out
|
mkdir $out
|
||||||
|
|
28
flake.lock
28
flake.lock
|
@ -3,11 +3,11 @@
|
||||||
"blog-source": {
|
"blog-source": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1672436100,
|
"lastModified": 1672443445,
|
||||||
"narHash": "sha256-shDvdyMXeTs2VVfIOOIQpF6eAe/5nAS8vZL2QA7ryIA=",
|
"narHash": "sha256-s7woTyMkyrtudu20bUcbyF5HXFXGa4NdM7H9id4mTVw=",
|
||||||
"ref": "master",
|
"ref": "master",
|
||||||
"rev": "e7cb818f055d91faabfe3eb4919b6508b29d28c6",
|
"rev": "0dfb964e99d20a8d630dacc7670e77bcbea8d43c",
|
||||||
"revCount": 609,
|
"revCount": 610,
|
||||||
"submodules": true,
|
"submodules": true,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://dev.danilafe.com/Web-Projects/blog-static.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"
|
"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": {
|
"flake-utils": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1648297722,
|
"lastModified": 1648297722,
|
||||||
|
@ -169,7 +150,6 @@
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"blog-source": "blog-source",
|
"blog-source": "blog-source",
|
||||||
"blog-source-localized": "blog-source-localized",
|
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"katex-html": "katex-html",
|
"katex-html": "katex-html",
|
||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_3"
|
||||||
|
|
11
flake.nix
11
flake.nix
|
@ -9,19 +9,12 @@
|
||||||
type = "git";
|
type = "git";
|
||||||
submodules = true;
|
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
|
let
|
||||||
buildersFor = system: import ./lib.nix {
|
buildersFor = system: import ./lib.nix {
|
||||||
inherit blog-source blog-source-localized;
|
inherit blog-source;
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
katex-html = katex-html.defaultPackage.${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 pkgs;
|
||||||
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
protocol = ssl: if ssl then "https://" else "http://";
|
||||||
website = settings: stdenv.mkDerivation {
|
website = settings: stdenv.mkDerivation {
|
||||||
inherit (settings) src ssl host;
|
inherit (settings) src ssl host;
|
||||||
name = "blog-static";
|
name = "blog-static";
|
||||||
version = settings.src.rev;
|
version = settings.src.rev or "dirty";
|
||||||
postPatch = with settings.replaceUrl; ''
|
|
||||||
substituteInPlace config.toml --replace ${from} ${to}
|
|
||||||
'';
|
|
||||||
publicPath = settings.path;
|
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;
|
builder = ./build/builder.sh;
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
hugo katex-html
|
hugo ruby stork katex-html
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
wrapHost = ssl: host: (if ssl then "https" else "http") + "://${host}";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
english = settings: website {
|
english = settings: website {
|
||||||
|
@ -26,22 +27,5 @@ in
|
||||||
drafts = settings.drafts or false;
|
drafts = settings.drafts or false;
|
||||||
src = blog-source;
|
src = blog-source;
|
||||||
path = ".";
|
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