From 5bef87be1f7218e15b57012db0a7099eae7d60f9 Mon Sep 17 00:00:00 2001 From: valentin gagarin Date: Wed, 13 Nov 2024 15:24:41 +0100 Subject: [PATCH] render content via structured DOM representation --- website/content/navigation.nix | 1 + website/presentation/default.nix | 62 +++++++++++++++++++----------- website/presentation/templates.nix | 14 ------- website/structure/document.nix | 2 + 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/website/content/navigation.nix b/website/content/navigation.nix index 3030399..1410f61 100644 --- a/website/content/navigation.nix +++ b/website/content/navigation.nix @@ -6,6 +6,7 @@ in menus.main = { label = "Main"; items = [ + { page = pages.index // { title = "Start"; }; } { menu.label = "For you"; menu.items = map (page: { inherit page; }) diff --git a/website/presentation/default.nix b/website/presentation/default.nix index 38ca658..9c78c0d 100644 --- a/website/presentation/default.nix +++ b/website/presentation/default.nix @@ -5,6 +5,14 @@ let types ; templates = import ./templates.nix { inherit lib; }; + render-html = document: + let + eval = lib.evalModules { + class = "DOM"; + modules = [ document (import ./dom.nix { inherit lib; }).document ]; + }; + in + toString eval.config; in { options.templates = @@ -38,30 +46,38 @@ in in { nav = lib.mkDefault templates.nav; - page = lib.mkDefault (config: page: templates.html { - head = '' - ${page.title} - - - ''; - body = '' - ${config.menus.main.outputs.html page} - ${builtins.readFile (commonmark page.name page.body)} - ''; + page = lib.mkDefault (config: page: render-html { + html = { + head = { + title.text = page.title; + meta.description = page.description; + link.canonical = lib.head page.locations; + }; + body.content = '' + ${config.menus.main.outputs.html page} + +

${page.title}

+ + ${builtins.readFile (commonmark page.name page.body)} + ''; + }; }); - article = lib.mkDefault (config: page: templates.html { - head = '' - ${page.title} - - ${with lib; join "\n" (map - (author: '''') - (if isList page.author then page.author else [page.author])) - } - ''; - body = '' - ${config.menus.main.outputs.html page} - ${builtins.readFile (commonmark page.name page.body)} - ''; + article = lib.mkDefault (config: page: render-html { + html = { + head = { + title.text = page.title; + meta.description = page.description; + meta.authors = if lib.isList page.author then page.author else [ page.author ]; + link.canonical = lib.head page.locations; + }; + body.content = '' + ${config.menus.main.outputs.html page} + +

${page.title}

+ + ${builtins.readFile (commonmark page.name page.body)} + ''; + }; }); }; diff --git a/website/presentation/templates.nix b/website/presentation/templates.nix index d33630b..c0d7f65 100644 --- a/website/presentation/templates.nix +++ b/website/presentation/templates.nix @@ -1,19 +1,5 @@ { lib }: rec { - html = { head, body }: '' - - - - - - - ${lib.indent " " head} - - - ${lib.indent " " body} - - - ''; nav = menu: page: let render-item = item: diff --git a/website/structure/document.nix b/website/structure/document.nix index eca89c8..8af04c3 100644 --- a/website/structure/document.nix +++ b/website/structure/document.nix @@ -46,6 +46,8 @@ in default = target: with lib; "${relativePath (head config.locations) (head target.locations)}.html"; }; outputs = mkOption { + # TODO: figure out how to make this overridable at any granularity. + # it should be possible with the DOM module now. description = '' Representations of the document in different formats '';