From 3d55fead09276ab7103cd34645892e074328c45d Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Thu, 6 Apr 2023 06:36:40 +0300 Subject: [PATCH] move config to nix, fix markdown conversion --- examples/site.nix | 4 ++++ examples/site/config.toml | 2 -- pkgs-lib.nix | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) delete mode 100644 examples/site/config.toml diff --git a/examples/site.nix b/examples/site.nix index 8c597c3..a98b96a 100644 --- a/examples/site.nix +++ b/examples/site.nix @@ -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"; diff --git a/examples/site/config.toml b/examples/site/config.toml deleted file mode 100644 index 279e063..0000000 --- a/examples/site/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -baseurl = "http://127.0.0.1:8080" -title = "test site" \ No newline at end of file diff --git a/pkgs-lib.nix b/pkgs-lib.nix index 7a07f60..8321d3e 100644 --- a/pkgs-lib.nix +++ b/pkgs-lib.nix @@ -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 = {