improvements
This commit is contained in:
parent
5bca7064e4
commit
8c562cd257
11
css.nix
11
css.nix
@ -1,15 +1,16 @@
|
|||||||
{ utils }:
|
{utils}: let
|
||||||
let
|
|
||||||
inherit (utils) mapAttrsToList concatStringsSep isList toString map;
|
inherit (utils) mapAttrsToList concatStringsSep isList toString map;
|
||||||
|
|
||||||
evalCssValue = value: if isList value then concatStringsSep ", " (map toString value) else toString value;
|
evalCssValue = value:
|
||||||
|
if isList value
|
||||||
|
then concatStringsSep ", " (map toString value)
|
||||||
|
else toString value;
|
||||||
evalInner = inner: concatStringsSep " " (mapAttrsToList (name: value: "${name}: ${evalCssValue value};") inner);
|
evalInner = inner: concatStringsSep " " (mapAttrsToList (name: value: "${name}: ${evalCssValue value};") inner);
|
||||||
css = maybeAttrs:
|
css = maybeAttrs:
|
||||||
if isList maybeAttrs
|
if isList maybeAttrs
|
||||||
then concatStringsSep " " maybeAttrs
|
then concatStringsSep " " maybeAttrs
|
||||||
else concatStringsSep " " (mapAttrsToList (name: inner: "${name} { ${evalInner inner} }") maybeAttrs);
|
else concatStringsSep " " (mapAttrsToList (name: inner: "${name} { ${evalInner inner} }") maybeAttrs);
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
inherit css;
|
inherit css;
|
||||||
|
|
||||||
media = rule: inner: ''
|
media = rule: inner: ''
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
{ tags, pkgs }:
|
{
|
||||||
with pkgs.htmlNix;
|
tags,
|
||||||
let
|
pkgs,
|
||||||
|
}:
|
||||||
|
with pkgs.htmlNix; let
|
||||||
index = with tags;
|
index = with tags;
|
||||||
html [
|
html [
|
||||||
(body [
|
(body [
|
||||||
@ -17,6 +19,9 @@ let
|
|||||||
])
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
site = { "index.html" = index; "ex.html" = ex; };
|
site = {
|
||||||
|
"index.html" = index;
|
||||||
|
"ex.html" = ex;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
mkServeFromSite site
|
mkServeFromSite site
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
{ pkgs, lib }:
|
{
|
||||||
let
|
pkgs,
|
||||||
|
lib,
|
||||||
|
}: let
|
||||||
inherit (pkgs) htmlNix;
|
inherit (pkgs) htmlNix;
|
||||||
src = ./site;
|
src = ./site;
|
||||||
in
|
in
|
||||||
htmlNix.mkServeFromSite (htmlNix.mkSiteFrom {
|
htmlNix.mkServeFromSite (htmlNix.mkSiteFrom {
|
||||||
inherit src;
|
inherit src;
|
||||||
templater = lib.templaters.basic;
|
templater = lib.templaters.basic;
|
||||||
local = true;
|
local = true;
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
tags: with tags;
|
tags:
|
||||||
html [
|
with tags;
|
||||||
(body [
|
html [
|
||||||
(p "Hello,")
|
(body [
|
||||||
(p "world!")
|
(p "Hello,")
|
||||||
])
|
(p "world!")
|
||||||
]
|
])
|
||||||
|
]
|
||||||
|
82
flake.nix
82
flake.nix
@ -4,50 +4,54 @@
|
|||||||
flakeUtils.url = "github:numtide/flake-utils";
|
flakeUtils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, flakeUtils, nixpkgs }:
|
outputs = {
|
||||||
let
|
self,
|
||||||
utils = import ./utils.nix;
|
flakeUtils,
|
||||||
|
nixpkgs,
|
||||||
|
}: let
|
||||||
|
utils = import ./utils.nix;
|
||||||
|
|
||||||
|
lib = {
|
||||||
|
# Convert Nix expressions to HTML
|
||||||
|
tags = import ./tags.nix {inherit utils;};
|
||||||
|
# Convert Nix expressions to CSS
|
||||||
|
css = import ./css.nix {inherit utils;};
|
||||||
|
|
||||||
|
# Various site templaters
|
||||||
|
templaters = {
|
||||||
|
# Basic templater with purecss, mobile responsive layout and supports posts
|
||||||
|
basic = import ./templaters/basic.nix;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = flakeUtils.lib.eachDefaultSystem (system: let
|
||||||
|
pkgs = nixpkgs.legacyPackagse.${system};
|
||||||
|
in {
|
||||||
lib = {
|
lib = {
|
||||||
# Convert Nix expressions to HTML
|
pkgsLib = import ./pkgs-lib.nix {
|
||||||
tags = import ./tags.nix { inherit utils; };
|
inherit pkgs;
|
||||||
# Convert Nix expressions to CSS
|
utils = utils // {inherit (lib) tags css;};
|
||||||
css = import ./css.nix { inherit utils; };
|
|
||||||
|
|
||||||
# Various site templaters
|
|
||||||
templaters = {
|
|
||||||
# Basic templater with purecss, mobile responsive layout and supports posts
|
|
||||||
basic = import ./templaters/basic.nix;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
overlay = final: prev: {
|
apps = with flakeUtils.lib; {
|
||||||
htmlNix = (import ./pkgs-lib.nix { pkgs = prev; utils = utils // { inherit (lib) tags css; }; }) // lib;
|
site = mkApp {
|
||||||
|
drv = import ./examples/site.nix {inherit lib pkgs;};
|
||||||
|
name = "serve";
|
||||||
|
};
|
||||||
|
basicServe = mkApp {
|
||||||
|
drv = import ./examples/serve.nix {
|
||||||
|
inherit (lib) tags;
|
||||||
|
inherit pkgs;
|
||||||
|
};
|
||||||
|
name = "serve";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
in
|
|
||||||
{ inherit overlay; } //
|
|
||||||
(flakeUtils.lib.eachDefaultSystem (system:
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
|
|
||||||
in
|
|
||||||
{
|
|
||||||
lib = lib // {
|
|
||||||
pkgsLib = import ./pkgs-lib.nix { inherit pkgs; utils = utils // { inherit (lib) tags css; }; };
|
|
||||||
};
|
|
||||||
|
|
||||||
apps = with flakeUtils.lib; {
|
examples = {
|
||||||
site = mkApp {
|
tags = import ./examples/tags.nix lib.tags;
|
||||||
drv = import ./examples/site.nix { inherit lib pkgs; };
|
};
|
||||||
name = "serve";
|
});
|
||||||
};
|
in
|
||||||
basicServe = mkApp {
|
outputs // {lib = outputs.lib // lib;};
|
||||||
drv = import ./examples/serve.nix { inherit (lib) tags; inherit pkgs; };
|
|
||||||
name = "serve";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
examples = {
|
|
||||||
tags = import ./examples/tags.nix lib.tags;
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
161
pkgs-lib.nix
161
pkgs-lib.nix
@ -1,93 +1,104 @@
|
|||||||
{ utils, pkgs }:
|
{
|
||||||
let
|
utils,
|
||||||
|
pkgs,
|
||||||
|
}: let
|
||||||
pkgBin = name: "${pkgs.${name}}/bin/${name}";
|
pkgBin = name: "${pkgs.${name}}/bin/${name}";
|
||||||
|
|
||||||
mkServePathScript = path: pkgs.writeScriptBin "serve" ''
|
mkServePathScript = path:
|
||||||
#!${pkgs.stdenv.shell}
|
pkgs.writeScriptBin "serve" ''
|
||||||
cd ${path}
|
#!${pkgs.stdenv.shell}
|
||||||
${pkgBin "caddy"} run --config Caddyfile
|
cd ${path}
|
||||||
'';
|
${pkgBin "caddy"} run --config Caddyfile
|
||||||
|
'';
|
||||||
|
|
||||||
mkSitePath = site:
|
mkSitePath = site: let
|
||||||
let
|
inherit (utils) recursiveAttrPaths concatStringsSep map;
|
||||||
inherit (utils) recursiveAttrPaths concatStringsSep map;
|
inherit (pkgs.lib) mapAttrsRecursive init last getAttrFromPath;
|
||||||
inherit (pkgs.lib) mapAttrsRecursive init last getAttrFromPath;
|
|
||||||
|
|
||||||
fileAttrPaths = recursiveAttrPaths site;
|
fileAttrPaths = recursiveAttrPaths site;
|
||||||
texts = mapAttrsRecursive (path: value: pkgs.writeText (concatStringsSep "-" path) value) site;
|
texts = mapAttrsRecursive (path: value: pkgs.writeText (concatStringsSep "-" path) value) site;
|
||||||
mkCreateFileCmd = path: value: let p = concatStringsSep "/" (init path); in "mkdir -p \"$out/${p}\" && ln -s \"${value}\" \"$out/${p}/${last path}\"";
|
mkCreateFileCmd = path: value: let p = concatStringsSep "/" (init path); in "mkdir -p \"$out/${p}\" && ln -s \"${value}\" \"$out/${p}/${last path}\"";
|
||||||
createFileCmds = map (path: mkCreateFileCmd path (getAttrFromPath path texts)) fileAttrPaths;
|
createFileCmds = map (path: mkCreateFileCmd path (getAttrFromPath path texts)) fileAttrPaths;
|
||||||
in
|
in
|
||||||
pkgs.runCommandLocal "site-path" { } ''
|
pkgs.runCommandLocal "site-path" {} ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
${concatStringsSep "\n" createFileCmds}
|
${concatStringsSep "\n" createFileCmds}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
parseMarkdown = name: contents:
|
parseMarkdown = name: contents:
|
||||||
pkgs.runCommandLocal name { } ''
|
pkgs.runCommandLocal name {} ''
|
||||||
printf ${pkgs.lib.escapeShellArg contents} | ${pkgBin "pandoc"} -f gfm > $out
|
printf ${pkgs.lib.escapeShellArg contents} | ${pkgBin "pandoc"} -f gfm > $out
|
||||||
'';
|
'';
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
inherit mkServePathScript mkSitePath parseMarkdown;
|
inherit mkServePathScript mkSitePath parseMarkdown;
|
||||||
|
|
||||||
mkServeFromSite = site: mkServePathScript (mkSitePath site);
|
mkServeFromSite = site: mkServePathScript (mkSitePath site);
|
||||||
mkSiteFrom = { src, templater, local ? false }:
|
mkSiteFrom = {
|
||||||
let
|
src,
|
||||||
inherit (utils) readDir readFile fromTOML mapAttrsToList sort elemAt;
|
templater,
|
||||||
inherit (pkgs.lib) nameValuePair head splitString pipe removeSuffix mapAttrs';
|
local ? false,
|
||||||
|
}: let
|
||||||
|
inherit (utils) readDir readFile fromTOML mapAttrsToList sort elemAt;
|
||||||
|
inherit (pkgs.lib) nameValuePair head splitString pipe removeSuffix mapAttrs';
|
||||||
|
|
||||||
postsRendered =
|
postsRendered = let
|
||||||
let path = src + "/posts"; in
|
path = src + "/posts";
|
||||||
pipe (readDir path) [
|
|
||||||
(mapAttrsToList (name: _:
|
|
||||||
nameValuePair
|
|
||||||
(head (splitString "." name))
|
|
||||||
(readFile (parseMarkdown name (readFile (path + "/${name}"))))
|
|
||||||
))
|
|
||||||
(sort (p: op:
|
|
||||||
let
|
|
||||||
extractDate = name: splitString "-" (head (splitString "_" name));
|
|
||||||
getPart = name: el: removeSuffix "0" (elemAt (extractDate name) el);
|
|
||||||
d = getPart p.name;
|
|
||||||
od = getPart op.name;
|
|
||||||
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"));
|
|
||||||
baseurl = if local then "http://localhost:8080" else siteConfig.baseurl or (throw "Need baseurl");
|
|
||||||
|
|
||||||
context = {
|
|
||||||
inherit utils pkgs baseurl;
|
|
||||||
config = siteConfig;
|
|
||||||
posts = postsRendered;
|
|
||||||
pages = pagesRendered;
|
|
||||||
site = {
|
|
||||||
"robots.txt" = ''
|
|
||||||
User-agent: *
|
|
||||||
Allow: /
|
|
||||||
'';
|
|
||||||
"Caddyfile" = ''
|
|
||||||
${baseurl}
|
|
||||||
|
|
||||||
handle_errors {
|
|
||||||
rewrite * /{http.error.status_code}.html
|
|
||||||
file_server
|
|
||||||
}
|
|
||||||
file_server
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
|
pipe (readDir path) [
|
||||||
|
(mapAttrsToList (
|
||||||
|
name: _:
|
||||||
|
nameValuePair
|
||||||
|
(head (splitString "." name))
|
||||||
|
(readFile (parseMarkdown name (readFile (path + "/${name}"))))
|
||||||
|
))
|
||||||
|
(sort (
|
||||||
|
p: op: let
|
||||||
|
extractDate = name: splitString "-" (head (splitString "_" name));
|
||||||
|
getPart = name: el: removeSuffix "0" (elemAt (extractDate name) el);
|
||||||
|
d = getPart p.name;
|
||||||
|
od = getPart op.name;
|
||||||
|
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"));
|
||||||
|
baseurl =
|
||||||
|
if local
|
||||||
|
then "http://localhost:8080"
|
||||||
|
else siteConfig.baseurl or (throw "Need baseurl");
|
||||||
|
|
||||||
|
context = {
|
||||||
|
inherit utils pkgs baseurl;
|
||||||
|
config = siteConfig;
|
||||||
|
posts = postsRendered;
|
||||||
|
pages = pagesRendered;
|
||||||
|
site = {
|
||||||
|
"robots.txt" = ''
|
||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
'';
|
||||||
|
"Caddyfile" = ''
|
||||||
|
${baseurl}
|
||||||
|
|
||||||
|
handle_errors {
|
||||||
|
rewrite * /{http.error.status_code}.html
|
||||||
|
file_server
|
||||||
|
}
|
||||||
|
file_server
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
(templater context).site;
|
(templater context).site;
|
||||||
}
|
}
|
||||||
|
30
tags.nix
30
tags.nix
@ -1,23 +1,31 @@
|
|||||||
{ utils }:
|
{utils}: let
|
||||||
let
|
|
||||||
inherit (utils) concatStrings mapAttrsToList genAttrs isAttrs isList range toString;
|
inherit (utils) concatStrings mapAttrsToList genAttrs isAttrs isList range toString;
|
||||||
|
|
||||||
evalAttrs = attrs: concatStrings (mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
|
evalAttrs = attrs: concatStrings (mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
|
||||||
evalChildren = children: if isList children then concatStrings children else children;
|
evalChildren = children:
|
||||||
|
if isList children
|
||||||
|
then concatStrings children
|
||||||
|
else children;
|
||||||
tag = name: maybeAttrs:
|
tag = name: maybeAttrs:
|
||||||
if isAttrs maybeAttrs
|
if isAttrs maybeAttrs
|
||||||
then (children: "<${name}${evalAttrs maybeAttrs}>${evalChildren children}</${name}>")
|
then (children: "<${name}${evalAttrs maybeAttrs}>${evalChildren children}</${name}>")
|
||||||
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 = ["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"];
|
||||||
noChildrenTags = genAttrs noChildrenTag noChildrenTagsToGen;
|
noChildrenTags = genAttrs noChildrenTag noChildrenTagsToGen;
|
||||||
in
|
in
|
||||||
tags // noChildrenTags // {
|
tags
|
||||||
inherit tag;
|
// noChildrenTags
|
||||||
mkLink = url: tags.a { href = url; };
|
// {
|
||||||
mkStylesheet = url: noChildrenTags.link { rel = "stylesheet"; href = url; };
|
inherit tag;
|
||||||
}
|
mkLink = url: tags.a {href = url;};
|
||||||
|
mkStylesheet = url:
|
||||||
|
noChildrenTags.link {
|
||||||
|
rel = "stylesheet";
|
||||||
|
href = url;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
{ utils, posts, pkgs, config, pages, site, baseurl, ... }@context:
|
{
|
||||||
let
|
utils,
|
||||||
|
posts,
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
pages,
|
||||||
|
site,
|
||||||
|
baseurl,
|
||||||
|
...
|
||||||
|
} @ 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) optional length splitString nameValuePair toInt range mapAttrs';
|
inherit (pkgs.lib) optional length splitString nameValuePair toInt range mapAttrs';
|
||||||
|
|
||||||
@ -9,67 +17,96 @@ let
|
|||||||
"${baseurl}/site.css"
|
"${baseurl}/site.css"
|
||||||
];
|
];
|
||||||
|
|
||||||
renderPost = { name, value }:
|
renderPost = {
|
||||||
let
|
name,
|
||||||
parts = splitString "_" name;
|
value,
|
||||||
id = elemAt parts 1;
|
}: let
|
||||||
in
|
parts = splitString "_" name;
|
||||||
with tags; article [
|
id = elemAt parts 1;
|
||||||
(a { href = "#${id}"; class = "postheader"; } (h2 { inherit id; } id))
|
in
|
||||||
(h3 ("date: " + (elemAt parts 0)))
|
with tags;
|
||||||
value
|
article [
|
||||||
];
|
(a {
|
||||||
|
href = "#${id}";
|
||||||
|
class = "postheader";
|
||||||
|
} (h2 {inherit id;} id))
|
||||||
|
(h3 ("date: " + (elemAt parts 0)))
|
||||||
|
value
|
||||||
|
];
|
||||||
|
|
||||||
pagesSection =
|
pagesSection =
|
||||||
(map
|
(map
|
||||||
(name: tags.div { class = "pure-u-1"; } (tags.a { href = "${baseurl}/${name}/"; class = "pagelink"; } name))
|
(name:
|
||||||
(mapAttrsToList (name: _: name) pages)) ++ [ (tags.div { class = "pure-u-1"; } (tags.a { href = "${baseurl}/"; class = "pagelink"; } "posts")) ];
|
tags.div {class = "pure-u-1";} (tags.a {
|
||||||
|
href = "${baseurl}/${name}/";
|
||||||
|
class = "pagelink";
|
||||||
|
}
|
||||||
|
name))
|
||||||
|
(mapAttrsToList (name: _: name) pages))
|
||||||
|
++ [
|
||||||
|
(tags.div {class = "pure-u-1";} (tags.a {
|
||||||
|
href = "${baseurl}/";
|
||||||
|
class = "pagelink";
|
||||||
|
} "posts"))
|
||||||
|
];
|
||||||
|
|
||||||
postsSectionContent = with tags; [
|
postsSectionContent = with tags;
|
||||||
(a { href = "#posts"; class = "postheader"; } (h1 "posts"))
|
[
|
||||||
] ++ (map renderPost posts);
|
(a {
|
||||||
|
href = "#posts";
|
||||||
|
class = "postheader";
|
||||||
|
} (h1 "posts"))
|
||||||
|
]
|
||||||
|
++ (map renderPost posts);
|
||||||
|
|
||||||
sidebarSection = optional ((length pagesSection) > 0) (
|
sidebarSection = optional ((length pagesSection) > 0) (
|
||||||
with tags; nav { class = "sidebar"; } ([
|
with tags;
|
||||||
(a { href = "#pages"; class = "postheader"; } (h1 "pages"))
|
nav {class = "sidebar";} [
|
||||||
(div { class = "pure-g"; } pagesSection)
|
(a {
|
||||||
])
|
href = "#pages";
|
||||||
|
class = "postheader";
|
||||||
|
} (h1 "pages"))
|
||||||
|
(div {class = "pure-g";} pagesSection)
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
mkPage = content: with tags;
|
mkPage = content:
|
||||||
''
|
with tags; ''
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
${html [
|
${html [
|
||||||
(head (stylesheets ++ [
|
(head (stylesheets
|
||||||
(title config.title)
|
++ [
|
||||||
(meta { name = "viewport"; content = "width=device-width, initial-scale=1"; })
|
(title config.title)
|
||||||
]))
|
(meta {
|
||||||
(body (sidebarSection ++ [ (div { class = "content"; } content) ]))
|
name = "viewport";
|
||||||
|
content = "width=device-width, initial-scale=1";
|
||||||
|
})
|
||||||
|
]))
|
||||||
|
(body (sidebarSection ++ [(div {class = "content";} content)]))
|
||||||
]}
|
]}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
stylesheet =
|
stylesheet = with utils.css; let
|
||||||
with utils.css;
|
marginMobile = {
|
||||||
let
|
margin-left = "3%";
|
||||||
marginMobile = {
|
margin-right = "3%";
|
||||||
margin-left = "3%";
|
};
|
||||||
margin-right = "3%";
|
in
|
||||||
};
|
|
||||||
in
|
|
||||||
css [
|
css [
|
||||||
(css (
|
(css (
|
||||||
(
|
(
|
||||||
mapAttrs'
|
mapAttrs'
|
||||||
(name: value: nameValuePair value { content = "\"${concatStrings (map (_: "#") (range 1 (toInt name)))} \""; })
|
(name: value: nameValuePair value {content = "\"${concatStrings (map (_: "#") (range 1 (toInt name)))} \"";})
|
||||||
(genAttrs (n: "h${toString n}:before") (map toString (range 1 6)))
|
(genAttrs (n: "h${toString n}:before") (map toString (range 1 6)))
|
||||||
) // {
|
)
|
||||||
|
// {
|
||||||
body = {
|
body = {
|
||||||
font-family = [ "Raleway" "Helvetica" "Arial" "sans-serif" ];
|
font-family = ["Raleway" "Helvetica" "Arial" "sans-serif"];
|
||||||
background = "#111111";
|
background = "#111111";
|
||||||
color = "#eeeeee";
|
color = "#eeeeee";
|
||||||
};
|
};
|
||||||
pre = {
|
pre = {
|
||||||
font-family = [ "Iosevka Term" "Iosevka" "monospace" ];
|
font-family = ["Iosevka Term" "Iosevka" "monospace"];
|
||||||
background = "#171A21";
|
background = "#171A21";
|
||||||
color = "#eeeeee";
|
color = "#eeeeee";
|
||||||
};
|
};
|
||||||
@ -101,22 +138,28 @@ let
|
|||||||
}
|
}
|
||||||
))
|
))
|
||||||
(media "max-width: 48em" {
|
(media "max-width: 48em" {
|
||||||
"nav.sidebar" = {
|
"nav.sidebar" =
|
||||||
position = "relative";
|
{
|
||||||
margin-top = "5%";
|
position = "relative";
|
||||||
} // marginMobile;
|
margin-top = "5%";
|
||||||
"div.content" = {
|
}
|
||||||
margin-top = 0;
|
// marginMobile;
|
||||||
} // marginMobile;
|
"div.content" =
|
||||||
|
{
|
||||||
|
margin-top = 0;
|
||||||
|
}
|
||||||
|
// marginMobile;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
in
|
in {
|
||||||
{
|
|
||||||
inherit stylesheets sidebarSection mkPage stylesheet;
|
inherit stylesheets sidebarSection mkPage stylesheet;
|
||||||
|
|
||||||
site = site // {
|
site =
|
||||||
"index.html" = mkPage postsSectionContent;
|
site
|
||||||
"404.html" = mkPage (tags.h1 "No such page");
|
// {
|
||||||
"site.css" = stylesheet;
|
"index.html" = mkPage postsSectionContent;
|
||||||
} // (mapAttrs (name: value: { "index.html" = mkPage value; }) pages);
|
"404.html" = mkPage (tags.h1 "No such page");
|
||||||
|
"site.css" = stylesheet;
|
||||||
|
}
|
||||||
|
// (mapAttrs (name: value: {"index.html" = mkPage value;}) pages);
|
||||||
}
|
}
|
||||||
|
46
utils.nix
46
utils.nix
@ -3,34 +3,36 @@ let
|
|||||||
|
|
||||||
mapAttrsToList = f: attrs: map (name: f name attrs.${name}) (builtins.attrNames attrs);
|
mapAttrsToList = f: attrs: map (name: f name attrs.${name}) (builtins.attrNames attrs);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit mapAttrsToList;
|
inherit mapAttrsToList;
|
||||||
|
|
||||||
recursiveAttrPaths = set:
|
recursiveAttrPaths = set: let
|
||||||
let
|
|
||||||
flattenIfHasList = x:
|
flattenIfHasList = x:
|
||||||
if (isList x) && (any isList x)
|
if (isList x) && (any isList x)
|
||||||
then concatMap flattenIfHasList x
|
then concatMap flattenIfHasList x
|
||||||
else [ x ];
|
else [x];
|
||||||
|
|
||||||
recurse = path: set:
|
recurse = path: set: let
|
||||||
let
|
g = name: value:
|
||||||
g =
|
if isAttrs value
|
||||||
name: value:
|
then recurse (path ++ [name]) value
|
||||||
if isAttrs value
|
else path ++ [name];
|
||||||
then recurse (path ++ [ name ]) value
|
in
|
||||||
else path ++ [ name ];
|
|
||||||
in
|
|
||||||
mapAttrsToList g set;
|
mapAttrsToList g set;
|
||||||
in
|
in
|
||||||
flattenIfHasList (recurse [ ] set);
|
flattenIfHasList (recurse [] set);
|
||||||
|
|
||||||
concatStrings = concatStringsSep "";
|
concatStrings = concatStringsSep "";
|
||||||
genAttrs = f: names: listToAttrs (map (n: { name = n; value = (f n); }) names);
|
genAttrs = f: names:
|
||||||
|
listToAttrs (map (n: {
|
||||||
|
name = n;
|
||||||
|
value = f n;
|
||||||
|
})
|
||||||
|
names);
|
||||||
|
|
||||||
range = first: last:
|
range = first: last:
|
||||||
if first > last then
|
if first > last
|
||||||
[ ]
|
then []
|
||||||
else
|
else genList (n: first + n) (last - first + 1);
|
||||||
genList (n: first + n) (last - first + 1);
|
}
|
||||||
} // builtins
|
// builtins
|
||||||
|
Loading…
Reference in New Issue
Block a user