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