forked from Fediversity/Fediversity
extract main document conversion
This commit is contained in:
parent
e4dd054d28
commit
0fbcedbd1a
|
@ -1,17 +1,38 @@
|
||||||
{ pkgs, lib, ... }:
|
{ pkgs, lib, ... }:
|
||||||
{
|
rec {
|
||||||
|
/**
|
||||||
|
Convert a Nix document to HTML
|
||||||
|
*/
|
||||||
|
html = document: name:
|
||||||
|
builtins.toFile "${name}.html" ''
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>${document.title}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
${builtins.readFile (commonmark document.body name)}
|
||||||
|
<body>
|
||||||
|
</html>
|
||||||
|
'';
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert a commonmark string to HTML
|
||||||
|
*/
|
||||||
|
commonmark = markdown: name:
|
||||||
|
pkgs.runCommand "${name}.html" { buildInputs = [ pkgs.cmark ]; } ''
|
||||||
|
cmark ${builtins.toFile "${name}.md" markdown} > $out
|
||||||
|
'';
|
||||||
|
|
||||||
files = dir: lib.mapAttrs'
|
files = dir: lib.mapAttrs'
|
||||||
(
|
(
|
||||||
name: value:
|
attrname: value:
|
||||||
let
|
let
|
||||||
html = "${lib.removeSuffix ".nix" name}.html";
|
document = import (dir + "/${attrname}");
|
||||||
md = "${lib.removeSuffix ".nix" name}.md";
|
name = lib.removeSuffix ".nix" attrname;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
name = html;
|
name = "${name}.html";
|
||||||
value = pkgs.runCommand html { buildInputs = with pkgs; [ cmark ]; } ''
|
value = html document "${name}.html";
|
||||||
cmark ${builtins.toFile md (import (dir + "/${name}")).body} > $out
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
(builtins.readDir dir);
|
(builtins.readDir dir);
|
||||||
|
|
Loading…
Reference in a new issue