forked from Fediversity/fediversity.eu
split out template library
This commit is contained in:
parent
8634df5833
commit
6a22b197ac
|
@ -4,6 +4,7 @@ let
|
||||||
mkOption
|
mkOption
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
|
templates = import ./templates.nix { inherit lib; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.templates = mkOption {
|
options.templates = mkOption {
|
||||||
|
@ -30,46 +31,25 @@ in
|
||||||
# TODO: reconsider using `page.outPath` and what to put into `locations`.
|
# TODO: reconsider using `page.outPath` and what to put into `locations`.
|
||||||
# maybe we can avoid having ".html" suffixes there.
|
# maybe we can avoid having ".html" suffixes there.
|
||||||
# since templates can output multiple files, `html` is merely one of many things we *could* produce.
|
# since templates can output multiple files, `html` is merely one of many things we *could* produce.
|
||||||
${page.outPath} = builtins.toFile "${page.name}.html" ''
|
${page.outPath} = builtins.toFile "${page.name}.html" (templates.html {
|
||||||
<html>
|
head = ''
|
||||||
<head>
|
<title>${page.title}</title>
|
||||||
<meta charset="utf-8" />
|
<meta name="description" content="${page.description}" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<link rel="canonical" href="${page.outPath}" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
'';
|
||||||
|
body = builtins.readFile (commonmark page.name page.body);
|
||||||
<title>${page.title}</title>
|
});
|
||||||
<meta name="description" content="${page.description}" />
|
|
||||||
<link rel="canonical" href="${page.outPath}" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
${lib.indent " " (builtins.readFile (commonmark page.name page.body))}
|
|
||||||
<body>
|
|
||||||
</html>
|
|
||||||
'';
|
|
||||||
});
|
});
|
||||||
article = lib.mkDefault (config: page: {
|
article = lib.mkDefault (config: page: {
|
||||||
# TODO: create static redirects from `tail page.locations`
|
# TODO: create static redirects from `tail page.locations`
|
||||||
${page.outPath} = builtins.toFile "${page.name}.html" ''
|
${page.outPath} = builtins.toFile "${page.name}.html" (templates.html {
|
||||||
<html>
|
head = ''
|
||||||
<head>
|
<title>${page.title}</title>
|
||||||
<meta charset="utf-8" />
|
<meta name="description" content="${page.description}" />
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta name="author" content="${with lib; if isList page.author then join ", " page.author else page.author}" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
'';
|
||||||
|
body = builtins.readFile (commonmark page.name page.body);
|
||||||
<title>${page.title}</title>
|
});
|
||||||
<meta name="description" content="${page.description}" />
|
|
||||||
${with lib;
|
|
||||||
if ! isNull page.author then
|
|
||||||
''<meta name="author" content="${if isList page.author then join ", " page.author else page.author}" />''
|
|
||||||
else ""
|
|
||||||
}
|
|
||||||
<link rel="canonical" href="${page.outPath}" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
${lib.indent " " (builtins.readFile (commonmark page.name page.body))}
|
|
||||||
<body>
|
|
||||||
</html>
|
|
||||||
'';
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
17
presentation/templates.nix
Normal file
17
presentation/templates.nix
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{ lib }:
|
||||||
|
{
|
||||||
|
html = { head, body }: ''
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
${lib.indent " " head}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
${lib.indent " " body}
|
||||||
|
<body>
|
||||||
|
</html>
|
||||||
|
'';
|
||||||
|
}
|
Reference in a new issue