feat: pages folder support

This commit is contained in:
dusk 2021-05-16 22:47:53 +03:00
parent 1cff9716ed
commit b614348b89
Signed by: dusk
GPG Key ID: 1D8F8FAF2294D6EA
5 changed files with 28 additions and 33 deletions

View File

@ -5,18 +5,5 @@ let
in in
htmlNix.mkServeFromSite (htmlNix.mkSiteFrom { htmlNix.mkServeFromSite (htmlNix.mkSiteFrom {
inherit src; inherit src;
templater = context: pkgs.lib.pipe context [ templater = lib.templaters.basic;
# Add basic template
lib.templaters.basic
# Add about page
({ site, mkPage, ... }@result: {
site = site // {
"about.html" = with lib.tags; mkPage [
(h1 "About")
(p "testy test test")
];
};
})
];
}) })

View File

@ -1,6 +1 @@
title = "test site" title = "test site"
[pages]
index = "index.html"
about = "about.html"
test = "404.html"

View File

@ -0,0 +1,3 @@
# About
testy test

View File

@ -34,7 +34,7 @@ in
mkSiteFrom = { src, templater }: mkSiteFrom = { src, templater }:
let let
inherit (utils) readDir readFile fromTOML mapAttrsToList sort elemAt; inherit (utils) readDir readFile fromTOML mapAttrsToList sort elemAt;
inherit (pkgs.lib) nameValuePair head splitString pipe removeSuffix; inherit (pkgs.lib) nameValuePair head splitString pipe removeSuffix mapAttrs';
postsRendered = postsRendered =
let path = src + "/posts"; in let path = src + "/posts"; in
@ -42,7 +42,7 @@ in
(mapAttrsToList (name: _: (mapAttrsToList (name: _:
nameValuePair nameValuePair
(head (splitString "." name)) (head (splitString "." name))
(parseMarkdown name (readFile (path + "/${name}"))) (readFile (parseMarkdown name (readFile (path + "/${name}"))))
)) ))
(sort (p: op: (sort (p: op:
let let
@ -54,12 +54,22 @@ in
!(((d 0) > (od 0)) && ((d 1) > (od 1)) && ((d 2) > (od 2))) !(((d 0) > (od 0)) && ((d 1) > (od 1)) && ((d 2) > (od 2)))
)) ))
]; ];
pagesRendered =
let path = src + "/pages"; in
mapAttrs'
(name: _:
nameValuePair
(head (splitString "." name))
(readFile (parseMarkdown name (readFile (path + "/${name}"))))
)
(readDir path);
siteConfig = fromTOML (readFile (src + "/config.toml")); siteConfig = fromTOML (readFile (src + "/config.toml"));
context = { context = {
inherit utils pkgs; inherit utils pkgs;
config = siteConfig; config = siteConfig;
posts = postsRendered; posts = postsRendered;
pages = pagesRendered;
}; };
in in
(templater context).site; (templater context).site;

View File

@ -1,7 +1,7 @@
{ utils, posts, pkgs, config, ... }@context: { utils, posts, pkgs, config, pages, ... }@context:
let let
inherit (utils) readFile mapAttrsToList tags fetchGit map elemAt; inherit (utils) readFile mapAttrsToList tags fetchGit map elemAt foldl';
inherit (pkgs.lib) optional length splitString; inherit (pkgs.lib) optional length splitString mapAttrs' nameValuePair;
stylesheets = map tags.mkStylesheet [ stylesheets = map tags.mkStylesheet [
"https://unpkg.com/purecss@2.0.6/build/pure-min.css" "https://unpkg.com/purecss@2.0.6/build/pure-min.css"
@ -17,22 +17,22 @@ let
with tags; article [ with tags; article [
(a { href = "#${id}"; class = "postheader"; } (h3 { inherit id; } ("## " + id))) (a { href = "#${id}"; class = "postheader"; } (h3 { inherit id; } ("## " + id)))
(h6 ("date: " + (elemAt parts 0))) (h6 ("date: " + (elemAt parts 0)))
(readFile value) value
]; ];
pages = pagesSection =
mapAttrsToList map
(name: relPath: tags.div { class = "pure-u-1"; } (tags.a { href = "./${relPath}"; class = "postheader"; } name)) (name: tags.div { class = "pure-u-1"; } (tags.a { href = "./${name}.html"; class = "postheader"; } name))
(config.pages or { }); ((mapAttrsToList (name: _: name) pages) ++ [ "index" ]);
postsSectionContent = with tags; [ postsSectionContent = with tags; [
(a { href = "#posts"; class = "postheader"; } (h1 "# posts")) (a { href = "#posts"; class = "postheader"; } (h1 "# posts"))
] ++ (map renderPost posts); ] ++ (map renderPost posts);
sidebarSection = optional ((length pages) > 0) ( sidebarSection = optional ((length pagesSection) > 0) (
with tags; nav { class = "sidebar"; } ([ with tags; nav { class = "sidebar"; } ([
(a { href = "#pages"; class = "postheader"; } (h1 "# pages")) (a { href = "#pages"; class = "postheader"; } (h1 "# pages"))
(div { class = "pure-g"; } pages) (div { class = "pure-g"; } pagesSection)
]) ])
); );
@ -100,5 +100,5 @@ in
site = { site = {
"index.html" = mkPage postsSectionContent; "index.html" = mkPage postsSectionContent;
"mine.css" = stylesheet; "mine.css" = stylesheet;
}; } // (mapAttrs' (name: value: nameValuePair (name + ".html") (mkPage value)) pages);
} }