feat: posts section
This commit is contained in:
parent
985cac1b89
commit
cdb60bfb44
2
tags.nix
2
tags.nix
@ -12,7 +12,7 @@
|
|||||||
else tag name {} maybeAttrs;
|
else tag name {} maybeAttrs;
|
||||||
noChildrenTag = name: attrs: "<${name} ${evalAttrs attrs}>";
|
noChildrenTag = name: attrs: "<${name} ${evalAttrs attrs}>";
|
||||||
|
|
||||||
tagsToGen = ["html" "head" "body" "div" "p" "a" "title" "code" "pre" "nav" "article"] ++ (map (n: "h${toString n}") (range 1 6));
|
tagsToGen = ["ul" "li" "html" "head" "body" "div" "p" "a" "title" "code" "pre" "nav" "article"] ++ (map (n: "h${toString n}") (range 1 6));
|
||||||
tags = genAttrs tag tagsToGen;
|
tags = genAttrs tag tagsToGen;
|
||||||
|
|
||||||
noChildrenTagsToGen = ["link" "meta"];
|
noChildrenTagsToGen = ["link" "meta"];
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
...
|
...
|
||||||
} @ context: let
|
} @ context: let
|
||||||
inherit (utils) readFile mapAttrsToList mapAttrs tags fetchGit map elemAt foldl' concatStrings genAttrs toString;
|
inherit (utils) readFile mapAttrsToList mapAttrs tags fetchGit map elemAt foldl' concatStrings genAttrs toString;
|
||||||
inherit (pkgs.lib) optionalAttrs optional length splitString nameValuePair toInt range mapAttrs';
|
inherit (pkgs.lib) optionalAttrs optional length splitString nameValuePair toInt range mapAttrs' singleton;
|
||||||
|
inherit (builtins) listToAttrs;
|
||||||
|
|
||||||
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,12 +18,21 @@
|
|||||||
"${baseurl}/site.css"
|
"${baseurl}/site.css"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
parsePostName = name: let
|
||||||
|
parts = splitString "_" name;
|
||||||
|
id = elemAt parts 1;
|
||||||
|
date = elemAt parts 0;
|
||||||
|
in {
|
||||||
|
inherit id date;
|
||||||
|
formatted = "${date} - ${id}";
|
||||||
|
};
|
||||||
|
|
||||||
renderPost = {
|
renderPost = {
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
}: let
|
}: let
|
||||||
parts = splitString "_" name;
|
parsed = parsePostName name;
|
||||||
id = elemAt parts 1;
|
inherit (parsed) id date;
|
||||||
in
|
in
|
||||||
with tags;
|
with tags;
|
||||||
article [
|
article [
|
||||||
@ -30,12 +40,18 @@
|
|||||||
href = "#${id}";
|
href = "#${id}";
|
||||||
class = "postheader";
|
class = "postheader";
|
||||||
} (h2 {inherit id;} id))
|
} (h2 {inherit id;} id))
|
||||||
(h3 ("date: " + (elemAt parts 0)))
|
(h3 ("date: " + date))
|
||||||
value
|
value
|
||||||
];
|
];
|
||||||
|
|
||||||
pagesSection =
|
pagesSection =
|
||||||
(map
|
[
|
||||||
|
(tags.div {class = "pure-u-1";} (tags.a {
|
||||||
|
href = "${baseurl}/";
|
||||||
|
class = "pagelink";
|
||||||
|
} "home"))
|
||||||
|
]
|
||||||
|
++ (map
|
||||||
(name:
|
(name:
|
||||||
tags.div {class = "pure-u-1";} (tags.a {
|
tags.div {class = "pure-u-1";} (tags.a {
|
||||||
href = "${baseurl}/${name}/";
|
href = "${baseurl}/${name}/";
|
||||||
@ -45,11 +61,27 @@
|
|||||||
(mapAttrsToList (name: _: name) pages))
|
(mapAttrsToList (name: _: name) pages))
|
||||||
++ [
|
++ [
|
||||||
(tags.div {class = "pure-u-1";} (tags.a {
|
(tags.div {class = "pure-u-1";} (tags.a {
|
||||||
href = "${baseurl}/";
|
href = "${baseurl}/posts/";
|
||||||
class = "pagelink";
|
class = "pagelink";
|
||||||
} "posts"))
|
} "posts"))
|
||||||
];
|
];
|
||||||
|
|
||||||
|
postsRendered = map renderPost posts;
|
||||||
|
|
||||||
|
postsLinks = with tags;
|
||||||
|
singleton
|
||||||
|
(ul (
|
||||||
|
map
|
||||||
|
(
|
||||||
|
post:
|
||||||
|
li (
|
||||||
|
a {href = "${baseurl}/${post.name}";}
|
||||||
|
(parsePostName post.name).formatted
|
||||||
|
)
|
||||||
|
)
|
||||||
|
posts
|
||||||
|
));
|
||||||
|
|
||||||
postsSectionContent = with tags;
|
postsSectionContent = with tags;
|
||||||
[
|
[
|
||||||
(a {
|
(a {
|
||||||
@ -57,7 +89,7 @@
|
|||||||
class = "postheader";
|
class = "postheader";
|
||||||
} (h1 "posts"))
|
} (h1 "posts"))
|
||||||
]
|
]
|
||||||
++ (map renderPost posts);
|
++ postsLinks;
|
||||||
|
|
||||||
sidebarSection = optional ((length pagesSection) > 0) (
|
sidebarSection = optional ((length pagesSection) > 0) (
|
||||||
with tags;
|
with tags;
|
||||||
@ -84,6 +116,12 @@
|
|||||||
|
|
||||||
indexPage = mkPage (context.indexContent or postsSectionContent);
|
indexPage = mkPage (context.indexContent or postsSectionContent);
|
||||||
|
|
||||||
|
pagesAndPosts =
|
||||||
|
pages
|
||||||
|
// listToAttrs (
|
||||||
|
map (post: nameValuePair post.name (renderPost post)) posts
|
||||||
|
);
|
||||||
|
|
||||||
stylesheet = with utils.css; let
|
stylesheet = with utils.css; let
|
||||||
marginMobile = {
|
marginMobile = {
|
||||||
margin-left = "3%";
|
margin-left = "3%";
|
||||||
@ -156,9 +194,10 @@ in {
|
|||||||
site
|
site
|
||||||
// {
|
// {
|
||||||
"index.html" = indexPage;
|
"index.html" = indexPage;
|
||||||
|
"posts"."index.html" = mkPage postsSectionContent;
|
||||||
"404.html" = mkPage (tags.h1 "No such page");
|
"404.html" = mkPage (tags.h1 "No such page");
|
||||||
"site.css" = stylesheet;
|
"site.css" = stylesheet;
|
||||||
}
|
}
|
||||||
// (mapAttrs (name: value: {"index.html" = mkPage value;}) pages)
|
// (mapAttrs (name: value: {"index.html" = mkPage value;}) pagesAndPosts)
|
||||||
// optionalAttrs (context ? resources) {inherit (context) resources;};
|
// optionalAttrs (context ? resources) {inherit (context) resources;};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user