diff --git a/examples/site/config.toml b/examples/site/config.toml index 1481ae6..279e063 100644 --- a/examples/site/config.toml +++ b/examples/site/config.toml @@ -1 +1,2 @@ +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 633b469..ed150d7 100644 --- a/pkgs-lib.nix +++ b/pkgs-lib.nix @@ -64,12 +64,20 @@ in ) (readDir path); siteConfig = fromTOML (readFile (src + "/config.toml")); + baseurl = siteConfig.baseurl or (throw "Need baseurl"); context = { - inherit utils pkgs; + inherit utils pkgs baseurl; config = siteConfig; posts = postsRendered; pages = pagesRendered; + site = { + "robots.txt" = '' + User-agent: * + Allow: / + Sitemap: ${baseurl}/sitemap.xml + ''; + }; }; in (templater context).site; diff --git a/templaters/basic.nix b/templaters/basic.nix index c26cd4e..61bf6c4 100644 --- a/templaters/basic.nix +++ b/templaters/basic.nix @@ -1,4 +1,4 @@ -{ utils, posts, pkgs, config, pages, ... }@context: +{ utils, posts, pkgs, config, pages, site, baseurl, ... }@context: let inherit (utils) readFile mapAttrsToList tags fetchGit map elemAt foldl'; inherit (pkgs.lib) optional length splitString mapAttrs' nameValuePair; @@ -6,7 +6,7 @@ let stylesheets = map tags.mkStylesheet [ "https://unpkg.com/purecss@2.0.6/build/pure-min.css" "https://unpkg.com/purecss@2.0.6/build/grids-responsive-min.css" - "mine.css" + "${baseurl}/site.css" ]; renderPost = { name, value }: @@ -22,8 +22,8 @@ let pagesSection = (map - (name: tags.div { class = "pure-u-1"; } (tags.a { href = "./${name}.html"; class = "postheader"; } name)) - (mapAttrsToList (name: _: name) pages)) ++ [ (tags.div { class = "pure-u-1"; } (tags.a { href = "./index.html"; class = "postheader"; } "posts")) ]; + (name: tags.div { class = "pure-u-1"; } (tags.a { href = "${baseurl}/${name}.html"; class = "postheader"; } name)) + (mapAttrsToList (name: _: name) pages)) ++ [ (tags.div { class = "pure-u-1"; } (tags.a { href = "${baseurl}/index.html"; class = "postheader"; } "posts")) ]; postsSectionContent = with tags; [ (a { href = "#posts"; class = "postheader"; } (h1 "# posts")) @@ -37,13 +37,16 @@ let ); mkPage = content: with tags; - html [ - (head (stylesheets ++ [ - (title config.title) - (meta { name = "viewport"; content = "width=device-width, initial-scale=1"; }) - ])) - (body (sidebarSection ++ [ (div { class = "content"; } content) ])) - ]; + '' + + ${html [ + (head (stylesheets ++ [ + (title config.title) + (meta { name = "viewport"; content = "width=device-width, initial-scale=1"; }) + ])) + (body (sidebarSection ++ [ (div { class = "content"; } content) ])) + ]} + ''; stylesheet = with utils.css; @@ -97,8 +100,8 @@ in { inherit stylesheets sidebarSection mkPage stylesheet; - site = { + site = site // { "index.html" = mkPage postsSectionContent; - "mine.css" = stylesheet; + "site.css" = stylesheet; } // (mapAttrs' (name: value: nameValuePair (name + ".html") (mkPage value)) pages); }