html.nix/templaters/basic.nix

84 lines
2.3 KiB
Nix
Raw Normal View History

2021-05-15 19:42:16 +03:00
{ utils, posts, pkgs, config, ... }@context:
let
inherit (utils) readFile mapAttrsToList tags fetchGit map;
inherit (pkgs.lib) flatten optional length;
2021-05-15 19:42:16 +03:00
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" "css/mine.css" ];
renderPost = name: value: with tags; article [
2021-05-15 21:52:25 +03:00
(a { href = "#${name}"; class = "postheader"; } (h3 { id = name; } ("## " + name)))
2021-05-15 19:42:16 +03:00
(readFile value)
];
allPosts = flatten (mapAttrsToList renderPost posts);
pages =
mapAttrsToList
(name: relPath: tags.div { class = "pure-u-1"; } (tags.a { href = "./${relPath}"; class = "postheader"; } name))
(config.pages or { });
postsSection = with tags; div { class = "posts"; } ([
(a { href = "#posts"; class = "postheader"; } (h1 "# posts"))
] ++ allPosts);
sidebarSection = optional ((length pages) > 0) (
with tags; nav { class = "sidebar"; } ([
(a { href = "#pages"; class = "postheader"; } (h1 "# pages"))
(div { class = "pure-g"; } pages)
])
);
2021-05-15 19:42:16 +03:00
in
{
2021-05-15 21:29:30 +03:00
"index.html" = with tags;
2021-05-15 19:42:16 +03:00
html [
(head (stylesheets ++ [
2021-05-15 19:42:16 +03:00
(title config.title)
2021-05-15 21:52:25 +03:00
(meta { name = "viewport"; content = "width=device-width, initial-scale=1"; })
]))
(body (sidebarSection ++ [ postsSection ]))
2021-05-15 19:42:16 +03:00
];
2021-05-15 21:29:30 +03:00
css = {
"mine.css" = ''
body {
font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
code {
font-family: "Iosevka Term", "Iosevka", monospace;
background: #000000cc;
color: #eeeeee;
}
2021-05-15 21:52:25 +03:00
a.postheader,a.postheader:hover {
2021-05-15 21:29:30 +03:00
color: inherit;
text-decoration: none;
}
a.postheader:hover {
2021-05-15 21:29:30 +03:00
text-decoration: underline;
}
2021-05-15 21:52:25 +03:00
div.posts {
margin-top: 5%;
margin-bottom: 5%;
margin-left: 20%;
margin-right: 10%;
}
nav.sidebar {
position: fixed;
2021-05-15 21:52:25 +03:00
top: 0;
margin-left: 3%;
z-index: 1000;
}
@media (max-width: 48em) {
nav.sidebar {
position: relative;
margin-top: 5%;
margin-left: 0;
margin-right: 0;
}
div.posts {
margin-top: 0;
margin-left: 0;
margin-right: 0;
}
2021-05-15 21:29:30 +03:00
}
'';
};
2021-05-15 19:42:16 +03:00
}