feat: pages folder support
This commit is contained in:
parent
1cff9716ed
commit
b614348b89
@ -5,18 +5,5 @@ let
|
||||
in
|
||||
htmlNix.mkServeFromSite (htmlNix.mkSiteFrom {
|
||||
inherit src;
|
||||
templater = context: pkgs.lib.pipe context [
|
||||
# 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")
|
||||
];
|
||||
};
|
||||
})
|
||||
];
|
||||
templater = lib.templaters.basic;
|
||||
})
|
||||
|
@ -1,6 +1 @@
|
||||
title = "test site"
|
||||
|
||||
[pages]
|
||||
index = "index.html"
|
||||
about = "about.html"
|
||||
test = "404.html"
|
3
examples/site/pages/about.md
Normal file
3
examples/site/pages/about.md
Normal file
@ -0,0 +1,3 @@
|
||||
# About
|
||||
|
||||
testy test
|
14
pkgs-lib.nix
14
pkgs-lib.nix
@ -34,7 +34,7 @@ in
|
||||
mkSiteFrom = { src, templater }:
|
||||
let
|
||||
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 =
|
||||
let path = src + "/posts"; in
|
||||
@ -42,7 +42,7 @@ in
|
||||
(mapAttrsToList (name: _:
|
||||
nameValuePair
|
||||
(head (splitString "." name))
|
||||
(parseMarkdown name (readFile (path + "/${name}")))
|
||||
(readFile (parseMarkdown name (readFile (path + "/${name}"))))
|
||||
))
|
||||
(sort (p: op:
|
||||
let
|
||||
@ -54,12 +54,22 @@ in
|
||||
!(((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"));
|
||||
|
||||
context = {
|
||||
inherit utils pkgs;
|
||||
config = siteConfig;
|
||||
posts = postsRendered;
|
||||
pages = pagesRendered;
|
||||
};
|
||||
in
|
||||
(templater context).site;
|
||||
|
@ -1,7 +1,7 @@
|
||||
{ utils, posts, pkgs, config, ... }@context:
|
||||
{ utils, posts, pkgs, config, pages, ... }@context:
|
||||
let
|
||||
inherit (utils) readFile mapAttrsToList tags fetchGit map elemAt;
|
||||
inherit (pkgs.lib) optional length splitString;
|
||||
inherit (utils) readFile mapAttrsToList tags fetchGit map elemAt foldl';
|
||||
inherit (pkgs.lib) optional length splitString mapAttrs' nameValuePair;
|
||||
|
||||
stylesheets = map tags.mkStylesheet [
|
||||
"https://unpkg.com/purecss@2.0.6/build/pure-min.css"
|
||||
@ -17,22 +17,22 @@ let
|
||||
with tags; article [
|
||||
(a { href = "#${id}"; class = "postheader"; } (h3 { inherit id; } ("## " + id)))
|
||||
(h6 ("date: " + (elemAt parts 0)))
|
||||
(readFile value)
|
||||
value
|
||||
];
|
||||
|
||||
pages =
|
||||
mapAttrsToList
|
||||
(name: relPath: tags.div { class = "pure-u-1"; } (tags.a { href = "./${relPath}"; class = "postheader"; } name))
|
||||
(config.pages or { });
|
||||
pagesSection =
|
||||
map
|
||||
(name: tags.div { class = "pure-u-1"; } (tags.a { href = "./${name}.html"; class = "postheader"; } name))
|
||||
((mapAttrsToList (name: _: name) pages) ++ [ "index" ]);
|
||||
|
||||
postsSectionContent = with tags; [
|
||||
(a { href = "#posts"; class = "postheader"; } (h1 "# posts"))
|
||||
] ++ (map renderPost posts);
|
||||
|
||||
sidebarSection = optional ((length pages) > 0) (
|
||||
sidebarSection = optional ((length pagesSection) > 0) (
|
||||
with tags; nav { class = "sidebar"; } ([
|
||||
(a { href = "#pages"; class = "postheader"; } (h1 "# pages"))
|
||||
(div { class = "pure-g"; } pages)
|
||||
(div { class = "pure-g"; } pagesSection)
|
||||
])
|
||||
);
|
||||
|
||||
@ -100,5 +100,5 @@ in
|
||||
site = {
|
||||
"index.html" = mkPage postsSectionContent;
|
||||
"mine.css" = stylesheet;
|
||||
};
|
||||
} // (mapAttrs' (name: value: nameValuePair (name + ".html") (mkPage value)) pages);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user