2021-05-15 04:11:35 +03:00
|
|
|
{ utils, pkgs }:
|
2021-05-15 04:15:00 +03:00
|
|
|
let
|
|
|
|
pkgBin = name: "${pkgs.${name}}/bin/${name}";
|
|
|
|
|
2021-05-15 04:02:06 +03:00
|
|
|
mkServePathScript = path: pkgs.writeScriptBin "serve" ''
|
|
|
|
#!${pkgs.stdenv.shell}
|
2021-05-15 02:39:30 +03:00
|
|
|
${pkgBin "miniserve"} --index index.html ${path}
|
|
|
|
'';
|
2021-05-15 04:02:06 +03:00
|
|
|
|
|
|
|
mkSitePath = site:
|
|
|
|
let
|
2021-05-15 04:11:35 +03:00
|
|
|
inherit (utils) recursiveAttrPaths concatStringsSep map;
|
|
|
|
inherit (pkgs.lib) mapAttrsRecursive init last getAttrFromPath;
|
|
|
|
|
|
|
|
fileAttrPaths = recursiveAttrPaths site;
|
|
|
|
texts = mapAttrsRecursive (path: value: pkgs.writeText (concatStringsSep "-" path) value) site;
|
|
|
|
mkCreateFileCmd = path: value: let p = concatStringsSep "/" (init path); in "mkdir -p $out/${p} && ln -s ${value} $out/${p}/${last path}";
|
|
|
|
createFileCmds = map (path: mkCreateFileCmd path (getAttrFromPath path texts)) fileAttrPaths;
|
2021-05-15 04:02:06 +03:00
|
|
|
in
|
|
|
|
pkgs.runCommand "site-path" { } ''
|
|
|
|
mkdir -p $out
|
2021-05-15 04:11:35 +03:00
|
|
|
${concatStringsSep "\n" createFileCmds}
|
2021-05-15 04:02:06 +03:00
|
|
|
'';
|
2021-05-15 19:42:16 +03:00
|
|
|
|
|
|
|
parseMarkdown = name: contents:
|
|
|
|
pkgs.runCommand name { } ''
|
|
|
|
printf "${contents}" | ${pkgBin "lowdown"} -o $out -
|
|
|
|
'';
|
2021-05-15 04:15:00 +03:00
|
|
|
in
|
|
|
|
{
|
2021-05-15 19:42:16 +03:00
|
|
|
inherit mkServePathScript mkSitePath parseMarkdown;
|
2021-05-15 04:15:00 +03:00
|
|
|
|
|
|
|
mkServeFromSite = site: mkServePathScript (mkSitePath site);
|
2021-05-15 19:42:16 +03:00
|
|
|
mkSiteFrom = { src, templater }:
|
|
|
|
let
|
|
|
|
inherit (utils) readDir readFile fromTOML;
|
|
|
|
inherit (pkgs.lib) mapAttrs' nameValuePair head splitString;
|
|
|
|
|
|
|
|
postsRendered =
|
|
|
|
let path = src + "/posts"; in
|
|
|
|
mapAttrs'
|
|
|
|
(name: _:
|
|
|
|
nameValuePair
|
|
|
|
(head (splitString "." name))
|
|
|
|
(parseMarkdown name (readFile (path + "/${name}")))
|
|
|
|
)
|
|
|
|
(readDir path);
|
|
|
|
siteConfig = fromTOML (readFile (src + "/config.toml"));
|
|
|
|
|
|
|
|
context = {
|
|
|
|
inherit utils pkgs;
|
|
|
|
config = siteConfig;
|
|
|
|
posts = postsRendered;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
templater context;
|
2021-05-15 02:39:30 +03:00
|
|
|
}
|