forked from Fediversity/fediversity.eu
Compare commits
4 commits
7581ed9368
...
3689353603
Author | SHA1 | Date | |
---|---|---|---|
3689353603 | |||
c6f44d5f8e | |||
c25cd72ee9 | |||
0d5db72310 |
|
@ -55,7 +55,7 @@ in
|
||||||
sorted = with lib; reverseList (sortOn (entry: entry.date) config.collections.news.entry);
|
sorted = with lib; reverseList (sortOn (entry: entry.date) config.collections.news.entry);
|
||||||
in
|
in
|
||||||
lib.join "\n" (map (article: ''
|
lib.join "\n" (map (article: ''
|
||||||
- ${article.date} [${article.title}](${article})
|
- ${article.date} [${article.title}](${link article})
|
||||||
'') sorted)
|
'') sorted)
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
27
lib.nix
27
lib.nix
|
@ -113,5 +113,32 @@ rec {
|
||||||
};
|
};
|
||||||
nestedTypes.elemType = elemType;
|
nestedTypes.elemType = elemType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
listOfUnique = elemType:
|
||||||
|
let
|
||||||
|
baseType = lib.types.listOf elemType;
|
||||||
|
in
|
||||||
|
baseType // {
|
||||||
|
merge = loc: defs:
|
||||||
|
let
|
||||||
|
# Keep track of which definition each value came from
|
||||||
|
defsWithValues = map
|
||||||
|
(def:
|
||||||
|
map (v: { inherit (def) file; value = v; }) def.value
|
||||||
|
)
|
||||||
|
defs;
|
||||||
|
flatDefs = lib.flatten defsWithValues;
|
||||||
|
|
||||||
|
# Check for duplicates while preserving source info
|
||||||
|
seen = builtins.foldl'
|
||||||
|
(acc: def:
|
||||||
|
if lib.lists.any (v: v.value == def.value) acc
|
||||||
|
then throw "The option `${lib.options.showOption loc}` has duplicate values (${toString def.value}) defined in ${def.file}"
|
||||||
|
else acc ++ [ def ]
|
||||||
|
) [ ]
|
||||||
|
flatDefs;
|
||||||
|
in
|
||||||
|
map (def: def.value) seen;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,9 @@ in
|
||||||
|
|
||||||
Each template function takes the complete site `config` and the document's data structure.
|
Each template function takes the complete site `config` and the document's data structure.
|
||||||
'';
|
'';
|
||||||
|
# TODO: this function should probably take a single attrs,
|
||||||
|
# otherwise it's quite inflexible.
|
||||||
|
# named parameters would also help with readability at the call site
|
||||||
type = recursiveAttrs (with types; functionTo (functionTo str));
|
type = recursiveAttrs (with types; functionTo (functionTo str));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,14 +37,15 @@ in
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
nav = lib.mkDefault templates.nav;
|
||||||
page = lib.mkDefault (config: page: templates.html {
|
page = lib.mkDefault (config: page: templates.html {
|
||||||
head = ''
|
head = ''
|
||||||
<title>${page.title}</title>
|
<title>${page.title}</title>
|
||||||
<meta name="description" content="${page.description}" />
|
<meta name="description" content="${page.description}" />
|
||||||
<link rel="canonical" href="${page.outPath}" />
|
<link rel="canonical" href="${lib.head page.locations}" />
|
||||||
'';
|
'';
|
||||||
body = ''
|
body = ''
|
||||||
${templates.nav { inherit page; menu = { menu = config.menus.main; }; }}
|
${config.menus.main.outputs.html page}
|
||||||
${builtins.readFile (commonmark page.name page.body)}
|
${builtins.readFile (commonmark page.name page.body)}
|
||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
|
@ -55,7 +59,7 @@ in
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
body = ''
|
body = ''
|
||||||
${templates.nav { inherit page; menu = { menu = config.menus.main; }; }}
|
${config.menus.main.outputs.html page}
|
||||||
${builtins.readFile (commonmark page.name page.body)}
|
${builtins.readFile (commonmark page.name page.body)}
|
||||||
'';
|
'';
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,17 +14,16 @@ rec {
|
||||||
<body>
|
<body>
|
||||||
</html>
|
</html>
|
||||||
'';
|
'';
|
||||||
nav = { page, menu }:
|
nav = menu: page:
|
||||||
let
|
let
|
||||||
render-item = item:
|
render-item = item:
|
||||||
if item ? menu then
|
if item ? menu then ''
|
||||||
''
|
<li>${item.menu.label}
|
||||||
<li>${item.menu.label}
|
${lib.indent " " (item.menu.outputs.html page)}
|
||||||
${lib.indent " " (nav { inherit page; menu = item; })}
|
</li>
|
||||||
''
|
''
|
||||||
else
|
else if item ? page then ''<li><a href="${page.link item.page}">${item.page.title}</a></li>''
|
||||||
if item ? page then ''<li><a href="${page.link item.page}">${item.page.title}</a></li>''
|
else ''<li><a href="${item.link.url}">${item.link.label}</a></li>''
|
||||||
else ''<li><a href="${item.link.url}">${item.link.label}</a></li>''
|
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
|
|
|
@ -14,9 +14,6 @@ in
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = name;
|
default = name;
|
||||||
};
|
};
|
||||||
# TODO: reconsider using `page.outPath` and what to put into `locations`.
|
|
||||||
# maybe we can avoid having ".html" suffixes there.
|
|
||||||
# since templates can output multiple files, `html` is merely one of many things we *could* produce.
|
|
||||||
locations = mkOption {
|
locations = mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
List of historic output locations for the resulting file
|
List of historic output locations for the resulting file
|
||||||
|
@ -46,15 +43,7 @@ in
|
||||||
# TODO: we may want links to other representations,
|
# TODO: we may want links to other representations,
|
||||||
# and currently the mapping of output types to output file
|
# and currently the mapping of output types to output file
|
||||||
# names is soft.
|
# names is soft.
|
||||||
default = target: with lib; "${relativePath config.outPath target.outPath}.html";
|
default = target: with lib; "${relativePath (head config.locations) (head target.locations)}.html";
|
||||||
};
|
|
||||||
# TODO: may not need it when using `link`; could repurpose it to render the default template
|
|
||||||
outPath = mkOption {
|
|
||||||
description = ''
|
|
||||||
Location of the page, used for transparently creating links
|
|
||||||
'';
|
|
||||||
type = types.str;
|
|
||||||
default = lib.head config.locations;
|
|
||||||
};
|
};
|
||||||
outputs = mkOption {
|
outputs = mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
|
|
|
@ -29,7 +29,7 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
content-types.navigation = { name, ... }: {
|
content-types.navigation = { name, config, ... }: {
|
||||||
options = {
|
options = {
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
description = "Symbolic name, used as a human-readable identifier";
|
description = "Symbolic name, used as a human-readable identifier";
|
||||||
|
@ -49,6 +49,15 @@ in
|
||||||
link = mkOption { type = submodule cfg.content-types.named-link; };
|
link = mkOption { type = submodule cfg.content-types.named-link; };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
outputs = mkOption {
|
||||||
|
description = ''
|
||||||
|
Representations of the navigation structure in different formats
|
||||||
|
|
||||||
|
It must be a function that takes the page on which the navigation is to be shown, such that relative links get computed correctly.
|
||||||
|
'';
|
||||||
|
type = with types; attrsOf (functionTo str);
|
||||||
|
default.html = cfg.templates.html.nav { menu = config; };
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue