move config to nix, fix markdown conversion

This commit is contained in:
dusk 2023-04-06 06:36:40 +03:00
parent 4dc070f01a
commit 3d55fead09
Signed by: dusk
GPG Key ID: 1D8F8FAF2294D6EA
3 changed files with 12 additions and 10 deletions

View File

@ -5,6 +5,10 @@ topArgs: {
src = ./site; src = ./site;
templater = topArgs.config.html-nix.lib.templaters.simple; templater = topArgs.config.html-nix.lib.templaters.simple;
local = true; local = true;
config = {
baseurl = "http://127.0.0.1:8080";
title = "test site";
};
}); });
in { in {
apps.site.program = "${siteServe}/bin/serve"; apps.site.program = "${siteServe}/bin/serve";

View File

@ -1,2 +0,0 @@
baseurl = "http://127.0.0.1:8080"
title = "test site"

View File

@ -68,9 +68,9 @@ in {
${l.concatStringsSep "\n" createFileCmds} ${l.concatStringsSep "\n" createFileCmds}
''; '';
parseMarkdown = name: contents: parseMarkdown = name: path:
pkgs.runCommandLocal name {} '' pkgs.runCommandLocal name {} ''
printf ${l.escapeShellArg contents} | ${pkgBin "pandoc"} -f gfm > $out ${pkgBin "pandoc"} ${path} -f gfm -o $out
''; '';
in { in {
html-nix.lib = { html-nix.lib = {
@ -80,7 +80,8 @@ in {
src, src,
templater, templater,
local ? false, local ? false,
}: let config ? {},
} @ args: let
postsRendered = let postsRendered = let
path = src + "/posts"; path = src + "/posts";
in in
@ -98,7 +99,7 @@ in {
if date == "" if date == ""
then null then null
else date; else date;
content = l.readFile (parseMarkdown id (l.readFile (path + "/${name}"))); content = l.readFile (parseMarkdown id (path + "/${name}"));
} }
)) ))
(l.sort ( (l.sort (
@ -123,19 +124,18 @@ in {
name: _: rec { name: _: rec {
displayName = l.head (l.splitString "." name); displayName = l.head (l.splitString "." name);
id = l.replaceStrings [" "] ["_"] displayName; id = l.replaceStrings [" "] ["_"] displayName;
content = l.readFile (parseMarkdown id (l.readFile (path + "/${name}"))); content = l.readFile (parseMarkdown id (path + "/${name}"));
} }
) )
(l.readDir path); (l.readDir path);
siteConfig = l.fromTOML (l.readFile (src + "/config.toml"));
baseurl = baseurl =
if local if local
then "http://localhost:8080" then "http://localhost:8080"
else siteConfig.baseurl or (throw "Need baseurl"); else args.config.baseurl or (throw "Need baseurl");
context = { context = {
inherit lib baseurl; inherit lib baseurl;
config = siteConfig; inherit (args) config;
posts = postsRendered; posts = postsRendered;
pages = pagesRendered; pages = pagesRendered;
site = { site = {