From 10f3d15a98c5e4c7d1604aa501f4b4a5560d674c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Wed, 19 Feb 2025 18:34:19 +0100 Subject: [PATCH] website: format --- website/content/default.nix | 252 ++-- website/content/events.nix | 40 +- website/content/events/2024-11-zurich-zhf.nix | 36 +- .../events/owc-annual-conference-2024.nix | 42 +- .../events/publicspaces-conference-2024.nix | 32 +- .../events/waag-state-internet-2024.nix | 40 +- website/content/navigation.nix | 27 +- website/content/news.nix | 32 +- website/content/news/2024-11-zurich-zhf.nix | 36 +- website/content/news/project-launch.nix | 30 +- website/default.nix | 36 +- website/lib.nix | 171 +-- website/presentation/default.nix | 101 +- website/presentation/dom.nix | 1179 +++++++++-------- website/presentation/style.nix | 64 +- website/presentation/templates.nix | 85 +- website/structure/article.nix | 97 +- website/structure/assets.nix | 34 +- website/structure/collections.nix | 100 +- website/structure/default.nix | 135 +- website/structure/event.nix | 155 ++- website/structure/navigation.nix | 122 +- website/structure/page.nix | 58 +- website/tests.nix | 33 +- 24 files changed, 1679 insertions(+), 1258 deletions(-) diff --git a/website/content/default.nix b/website/content/default.nix index daccf44..f1d19ea 100644 --- a/website/content/default.nix +++ b/website/content/default.nix @@ -9,124 +9,160 @@ in collections.news.type = cfg.content-types.article; collections.events.type = cfg.content-types.event; - pages.index = { config, link, ... }: { - title = "Welcome to the Fediversity project"; - description = "Fediversity web site"; - summary = '' - This web site hosts up-to-date information about the the NGI Zero Fediversity project. - ''; - body = '' - ${pages.fediversity.summary} + pages.index = + { config, link, ... }: + { + title = "Welcome to the Fediversity project"; + description = "Fediversity web site"; + summary = '' + This web site hosts up-to-date information about the the NGI Zero Fediversity project. + ''; + body = '' + ${pages.fediversity.summary} - [Learn more about Fediversity](${link pages.fediversity}) - ''; - outputs.html = (cfg.templates.html.page config).override (final: prev: { - html = { - head.title.text = "Fediversity"; - head.link.stylesheets = prev.html.head.link.stylesheets ++ [ - { href = "${link cfg.assets."index.css"}"; } - ]; - body.content = - let - to-section = { heading, body, attrs ? { } }: { - section = { - heading.content = heading; - inherit attrs; - content = [ - (cfg.templates.html.markdown { - name = "${config.name}-${lib.slug heading}"; - inherit body; - }) - ]; - }; - }; - in - [ - (lib.head prev.html.body.content) - { - section = { - attrs = { }; - heading.content = config.title; - content = [ - (cfg.templates.html.markdown { inherit (config) name body; }) - ] - ++ - (map to-section [ + [Learn more about Fediversity](${link pages.fediversity}) + ''; + outputs.html = (cfg.templates.html.page config).override ( + final: prev: { + html = { + head.title.text = "Fediversity"; + head.link.stylesheets = prev.html.head.link.stylesheets ++ [ + { href = "${link cfg.assets."index.css"}"; } + ]; + body.content = + let + to-section = { - heading = "Fediversity grants"; - body = '' - ${pages.grants.summary} - - [Learn more about Fediversity grants](${link pages.grants}) - ''; - } + heading, + body, + attrs ? { }, + }: { - heading = "Consortium"; - body = '' - The Consortium behind the Fediversity project is a cooperation between NLnet, Open Internet Discourse Foundation, NORDUnet and Tweag. + section = { + heading.content = heading; + inherit attrs; + content = [ + (cfg.templates.html.markdown { + name = "${config.name}-${lib.slug heading}"; + inherit body; + }) + ]; + }; + }; + in + [ + (lib.head prev.html.body.content) + { + section = { + attrs = { }; + heading.content = config.title; + content = + [ + (cfg.templates.html.markdown { inherit (config) name body; }) + ] + ++ (map to-section [ + { + heading = "Fediversity grants"; + body = '' + ${pages.grants.summary} - ${toString (map (partner: '' - ### ${partner.title} + [Learn more about Fediversity grants](${link pages.grants}) + ''; + } + { + heading = "Consortium"; + body = '' + The Consortium behind the Fediversity project is a cooperation between NLnet, Open Internet Discourse Foundation, NORDUnet and Tweag. - ${partner.summary} + ${toString ( + map + (partner: '' + ### ${partner.title} - [Read more about ${partner.title}](${link partner}) - '') (with pages; [ nlnet oid tweag nordunet ]))} - ''; - } - { - heading = "Fediverse explained"; - body = '' - ${toString (map (role: '' - ### ${role.title} + ${partner.summary} - ${role.summary} + [Read more about ${partner.title}](${link partner}) + '') + ( + with pages; + [ + nlnet + oid + tweag + nordunet + ] + ) + )} + ''; + } + { + heading = "Fediverse explained"; + body = '' + ${toString ( + map + (role: '' + ### ${role.title} - [Read more about ${role.title}](${link role}) - '') (with pages; [ individuals developers european-commission ]))} - ''; - } - ]); - }; - } - ] - ++ - (map to-section [ - { - heading = "News"; - attrs = { class = [ "collection" ]; }; - body = - let - sorted = with lib; reverseList (sortOn (entry: entry.date) cfg.collections.news.entry); - in - lib.join "\n" (map - (article: '' - - ${article.date} [${article.title}](${link article}) - '') - sorted); - } - { - heading = "Events"; - attrs = { class = [ "collection" ]; }; - body = - let - sorted = with lib; reverseList (sortOn (entry: entry.start-date) cfg.collections.events.entry); - in - lib.join "\n" (map - (article: '' - - ${article.start-date} [${article.title}](${link article}) - '') - sorted); - } - ]); - }; + ${role.summary} - }); - }; + [Read more about ${role.title}](${link role}) + '') + ( + with pages; + [ + individuals + developers + european-commission + ] + ) + )} + ''; + } + ]); + }; + } + ] + ++ (map to-section [ + { + heading = "News"; + attrs = { + class = [ "collection" ]; + }; + body = + let + sorted = with lib; reverseList (sortOn (entry: entry.date) cfg.collections.news.entry); + in + lib.join "\n" ( + map (article: '' + - ${article.date} [${article.title}](${link article}) + '') sorted + ); + } + { + heading = "Events"; + attrs = { + class = [ "collection" ]; + }; + body = + let + sorted = with lib; reverseList (sortOn (entry: entry.start-date) cfg.collections.events.entry); + in + lib.join "\n" ( + map (article: '' + - ${article.start-date} [${article.title}](${link article}) + '') sorted + ); + } + ]); + }; - assets."index.css".path = with lib; builtins.toFile - "index.css" - '' + } + ); + }; + + assets."index.css".path = + with lib; + builtins.toFile "index.css" '' section h1, section h2, section h3 { text-align: center; diff --git a/website/content/events.nix b/website/content/events.nix index 450c50f..6d92ffb 100644 --- a/website/content/events.nix +++ b/website/content/events.nix @@ -1,22 +1,26 @@ { config, lib, ... }: { - pages.events = { link, ... }: rec { - title = "Events"; - description = "Events related to the Fediverse and NixOS"; - summary = description; - body = - with lib; - let - events = map - (event: with lib; '' - ## [${event.title}](${link event}) + pages.events = + { link, ... }: + rec { + title = "Events"; + description = "Events related to the Fediverse and NixOS"; + summary = description; + body = + with lib; + let + events = map ( + event: with lib; '' + ## [${event.title}](${link event}) - ${event.start-date} ${optionalString (!isNull event.end-date && event.end-date != event.start-date) "to ${event.end-date}"} in ${event.location} - '') - config.collections.events.entry; - in - '' - ${join "\n" events} - ''; - }; + ${event.start-date} ${ + optionalString (!isNull event.end-date && event.end-date != event.start-date) "to ${event.end-date}" + } in ${event.location} + '' + ) config.collections.events.entry; + in + '' + ${join "\n" events} + ''; + }; } diff --git a/website/content/events/2024-11-zurich-zhf.nix b/website/content/events/2024-11-zurich-zhf.nix index da7f225..ab0e567 100644 --- a/website/content/events/2024-11-zurich-zhf.nix +++ b/website/content/events/2024-11-zurich-zhf.nix @@ -1,23 +1,25 @@ { config, lib, ... }: { - collections.events.entry = { link, ... }: { - title = "NixOS 24.11 ZHF hackathon"; - name = "zhf-24-11"; - description = "NixOS 24.11 ZHF hackathon in Zürich"; - start-date = "2024-11-23"; - end-date = "2024-11-24"; - start-time = "10:00"; - end-time = "17:00"; - location = "OST Campus Rapperswil"; - body = '' - The biannual [Zürich NixOS ZHF hackathon](https://zurich.nix.ug/) has become somewhat of an institution for maintaining the tradition of preparing the upcoming NixOS release. + collections.events.entry = + { link, ... }: + { + title = "NixOS 24.11 ZHF hackathon"; + name = "zhf-24-11"; + description = "NixOS 24.11 ZHF hackathon in Zürich"; + start-date = "2024-11-23"; + end-date = "2024-11-24"; + start-time = "10:00"; + end-time = "17:00"; + location = "OST Campus Rapperswil"; + body = '' + The biannual [Zürich NixOS ZHF hackathon](https://zurich.nix.ug/) has become somewhat of an institution for maintaining the tradition of preparing the upcoming NixOS release. - The main goal of the two-day gathering is to bring down the number of build failures on the [continuous integration system Hydra](https://status.nixos.org/) before the release: ZHF stands for *Zero Hydra Failures*. - It also presents a great opportunity to learn Nix, squash bugs together, get to know each other, discuss current events, and make plans for the future. + The main goal of the two-day gathering is to bring down the number of build failures on the [continuous integration system Hydra](https://status.nixos.org/) before the release: ZHF stands for *Zero Hydra Failures*. + It also presents a great opportunity to learn Nix, squash bugs together, get to know each other, discuss current events, and make plans for the future. - This is the greatest event in the series so far, with more than 40 participants from all over Europe, including many high-profile contributors and maintainers in the Nix ecosystem. + This is the greatest event in the series so far, with more than 40 participants from all over Europe, including many high-profile contributors and maintainers in the Nix ecosystem. - [Fediversity engineers attended](${link config.collections.news.by-name.zhf-24-11}) to present prototypes and exchange ideas with other developers. - ''; - }; + [Fediversity engineers attended](${link config.collections.news.by-name.zhf-24-11}) to present prototypes and exchange ideas with other developers. + ''; + }; } diff --git a/website/content/events/owc-annual-conference-2024.nix b/website/content/events/owc-annual-conference-2024.nix index 39d495f..f44d520 100644 --- a/website/content/events/owc-annual-conference-2024.nix +++ b/website/content/events/owc-annual-conference-2024.nix @@ -1,24 +1,26 @@ { ... }: { - collections.events.entry = { ... }: { - title = "OW2con 2024"; - description = "OW2con is the annual European open source conference in Paris"; - start-date = "2024-06-11"; - end-date = "2024-06-12"; - start-time = "09:00"; - end-time = "18:00"; - location = "Paris-Chatillon"; - body = '' - OW2con is the European open source conference organized by OW2. - An international meeting of developpers, IT companies, academics and non-profit organizations, OW2con brings together the entire open source community, during two days of presentations ranging from tech topics to business and ethical issues of open source. - It also offers a unique opportunity to establish contact with peers through friendly networking sessions. - OW2con is [open](https://www.ngi.eu/event/open-source-community-annual-conference-2024/) to all, the event is free and all sessions are held in English. + collections.events.entry = + { ... }: + { + title = "OW2con 2024"; + description = "OW2con is the annual European open source conference in Paris"; + start-date = "2024-06-11"; + end-date = "2024-06-12"; + start-time = "09:00"; + end-time = "18:00"; + location = "Paris-Chatillon"; + body = '' + OW2con is the European open source conference organized by OW2. + An international meeting of developpers, IT companies, academics and non-profit organizations, OW2con brings together the entire open source community, during two days of presentations ranging from tech topics to business and ethical issues of open source. + It also offers a unique opportunity to establish contact with peers through friendly networking sessions. + OW2con is [open](https://www.ngi.eu/event/open-source-community-annual-conference-2024/) to all, the event is free and all sessions are held in English. - The OW2con’24 call for presentations is open. - This year we are giving the highlight on the theme of open source funding: - What are the current solutions for innovators, start-ups or ISVs to finance their development? - Private or public financing? - Are national and European public policies up to the challenges? - ''; - }; + The OW2con’24 call for presentations is open. + This year we are giving the highlight on the theme of open source funding: + What are the current solutions for innovators, start-ups or ISVs to finance their development? + Private or public financing? + Are national and European public policies up to the challenges? + ''; + }; } diff --git a/website/content/events/publicspaces-conference-2024.nix b/website/content/events/publicspaces-conference-2024.nix index 35fbe7d..3f2af58 100644 --- a/website/content/events/publicspaces-conference-2024.nix +++ b/website/content/events/publicspaces-conference-2024.nix @@ -1,18 +1,20 @@ { ... }: { - collections.events.entry = { ... }: { - title = "PublicSpaces Conference 2024"; - description = "A conference by PublicSpaces, Taking Back the Internet."; - start-date = "2024-06-06"; - end-date = "2024-06-07"; - start-time = "09:00"; - end-time = "18:00"; - location = "Pakhuis de Zwijger - Amsterdam"; - body = '' - On June 6th and 7th, PublicSpaces and Waag Futurelab proudly present the fourth edition of the PublicSpaces conference under the theme 'Empowering the Internet'. - Held at Pakhuis de Zwijger, this two-day event will feature panels, keynotes, roundtable discussions, lectures, as well as art and cultural showcases, all aimed at collectively shaping the rules for a more inclusive internet. - Join us as we navigate towards a digital landscape where everyone has a voice. - For more information, check out the [website](https://publicspaces.net/2024/02/01/save-the-date-publicspaces-conferentie-2024/) - ''; - }; + collections.events.entry = + { ... }: + { + title = "PublicSpaces Conference 2024"; + description = "A conference by PublicSpaces, Taking Back the Internet."; + start-date = "2024-06-06"; + end-date = "2024-06-07"; + start-time = "09:00"; + end-time = "18:00"; + location = "Pakhuis de Zwijger - Amsterdam"; + body = '' + On June 6th and 7th, PublicSpaces and Waag Futurelab proudly present the fourth edition of the PublicSpaces conference under the theme 'Empowering the Internet'. + Held at Pakhuis de Zwijger, this two-day event will feature panels, keynotes, roundtable discussions, lectures, as well as art and cultural showcases, all aimed at collectively shaping the rules for a more inclusive internet. + Join us as we navigate towards a digital landscape where everyone has a voice. + For more information, check out the [website](https://publicspaces.net/2024/02/01/save-the-date-publicspaces-conferentie-2024/) + ''; + }; } diff --git a/website/content/events/waag-state-internet-2024.nix b/website/content/events/waag-state-internet-2024.nix index a4608bd..0c6d607 100644 --- a/website/content/events/waag-state-internet-2024.nix +++ b/website/content/events/waag-state-internet-2024.nix @@ -1,25 +1,27 @@ { ... }: { - collections.events.entry = { ... }: { - title = "State of the Internet 2024"; - description = "The State of the Internet 2024 by Waag"; - start-date = "2024-05-16"; - end-date = "2024-05-16"; - start-time = "18:00"; - end-time = "20:00"; - location = "OBA Oosterdok - Amsterdam"; - body = '' - Join us at the State of the Internet 2024, where Waag Futurelab, alongside the Municipality of Amsterdam and the OBA, delves into the depths of the online realm. - Featuring Kim van Sparrentak, Member of the European Parliament, discussing Europe's efforts to regulate Big Tech and enhance digital rights. - Explore the impact of pivotal European laws like the GDPR and AI Act while celebrating 30 years of Waag Futurelab's dedication to democratizing technology access for all. + collections.events.entry = + { ... }: + { + title = "State of the Internet 2024"; + description = "The State of the Internet 2024 by Waag"; + start-date = "2024-05-16"; + end-date = "2024-05-16"; + start-time = "18:00"; + end-time = "20:00"; + location = "OBA Oosterdok - Amsterdam"; + body = '' + Join us at the State of the Internet 2024, where Waag Futurelab, alongside the Municipality of Amsterdam and the OBA, delves into the depths of the online realm. + Featuring Kim van Sparrentak, Member of the European Parliament, discussing Europe's efforts to regulate Big Tech and enhance digital rights. + Explore the impact of pivotal European laws like the GDPR and AI Act while celebrating 30 years of Waag Futurelab's dedication to democratizing technology access for all. - The event takes place at: + The event takes place at: - OBA Oosterdok
- Oosterdokskade 143
- 1011 DK Amsterdam + OBA Oosterdok
+ Oosterdokskade 143
+ 1011 DK Amsterdam - Registration available [here](https://waag.org/nl/event/de-staat-van-het-internet-2024-met-kim-van-sparrentak/). - ''; - }; + Registration available [here](https://waag.org/nl/event/de-staat-van-het-internet-2024-met-kim-van-sparrentak/). + ''; + }; } diff --git a/website/content/navigation.nix b/website/content/navigation.nix index 770fe29..2beb657 100644 --- a/website/content/navigation.nix +++ b/website/content/navigation.nix @@ -6,16 +6,33 @@ in menus.main = { label = "Main"; items = [ - { page = pages.index // { title = "Start"; }; } + { + page = pages.index // { + title = "Start"; + }; + } { menu.label = "For you"; - menu.items = map (page: { inherit page; }) - (with pages; [ individuals developers european-commission ]); + menu.items = map (page: { inherit page; }) ( + with pages; + [ + individuals + developers + european-commission + ] + ); } { menu.label = "Consortium"; - menu.items = map (page: { inherit page; }) - (with pages; [ nlnet oid tweag nordunet ]); + menu.items = map (page: { inherit page; }) ( + with pages; + [ + nlnet + oid + tweag + nordunet + ] + ); } { page = pages.fediversity; } { page = pages.grants; } diff --git a/website/content/news.nix b/website/content/news.nix index b689cf6..96d7c16 100644 --- a/website/content/news.nix +++ b/website/content/news.nix @@ -1,24 +1,24 @@ { config, lib, ... }: { - pages.news = { link, ... }: rec { - title = "News"; - description = "News about Fediversity"; - summary = description; - body = - with lib; - let - news = map - (article: '' + pages.news = + { link, ... }: + rec { + title = "News"; + description = "News about Fediversity"; + summary = description; + body = + with lib; + let + news = map (article: '' ## [${article.title}](${link article}) ${article.date} by ${article.author} ${article.summary} - '') - config.collections.news.entry; - in - '' - ${join "\n\n" news} - ''; - }; + '') config.collections.news.entry; + in + '' + ${join "\n\n" news} + ''; + }; } diff --git a/website/content/news/2024-11-zurich-zhf.nix b/website/content/news/2024-11-zurich-zhf.nix index 08d1202..84a8a05 100644 --- a/website/content/news/2024-11-zurich-zhf.nix +++ b/website/content/news/2024-11-zurich-zhf.nix @@ -1,22 +1,24 @@ { config, lib, ... }: { - collections.news.entry = { link, ... }: rec { - name = "zhf-24-11"; - title = "NixOS 24.11 release hackathon and workshop"; - description = "Fediversity engineers met in Zürich at a NixOS 24.11 ZHF hackathon"; - date = "2024-11-28"; - author = "Valentin Gagarin"; - summary = '' - Fediversity engineers met in Zürich at a [NixOS 24.11 ZHF hackathon](${link config.collections.events.by-name.zhf-24-11}) to present prototypes and exchange ideas with the Nix community. - ''; - body = '' - ${summary} + collections.news.entry = + { link, ... }: + rec { + name = "zhf-24-11"; + title = "NixOS 24.11 release hackathon and workshop"; + description = "Fediversity engineers met in Zürich at a NixOS 24.11 ZHF hackathon"; + date = "2024-11-28"; + author = "Valentin Gagarin"; + summary = '' + Fediversity engineers met in Zürich at a [NixOS 24.11 ZHF hackathon](${link config.collections.events.by-name.zhf-24-11}) to present prototypes and exchange ideas with the Nix community. + ''; + body = '' + ${summary} - Robert held a lightning talk on the design of [NixOps4](https://github.com/nixops4/nixops4), which is currently in the prototype stage of development. - Before that, Nicolas had already shown an internal demonstration that NixOps4 is capable of deploying multiple NixOS services in the Fediversity test environment. + Robert held a lightning talk on the design of [NixOps4](https://github.com/nixops4/nixops4), which is currently in the prototype stage of development. + Before that, Nicolas had already shown an internal demonstration that NixOps4 is capable of deploying multiple NixOS services in the Fediversity test environment. - In the afternoon, Robert, Valentin, and Koen got together with Eli from [Thymis](https://thymis.io) and Johannes from [Clan](https://clan.lol/) to walk each other through the architecture of their respective systems. - This was an extraordinarily fruitful encounter that helped us to identify overlaps and potential for future collaboration! - ''; - }; + In the afternoon, Robert, Valentin, and Koen got together with Eli from [Thymis](https://thymis.io) and Johannes from [Clan](https://clan.lol/) to walk each other through the architecture of their respective systems. + This was an extraordinarily fruitful encounter that helped us to identify overlaps and potential for future collaboration! + ''; + }; } diff --git a/website/content/news/project-launch.nix b/website/content/news/project-launch.nix index 63472b6..30a773c 100644 --- a/website/content/news/project-launch.nix +++ b/website/content/news/project-launch.nix @@ -1,19 +1,21 @@ { config, lib, ... }: { - collections.news.entry = { link, ... }: { - title = "Fediversity project publicly announced"; - description = "The Fediversity project has officially been announced"; - date = "2024-01-01"; - author = "Laurens Hof"; - summary = '' - We are pleased to introduce the launch of our new website dedicated to the Fediversity project. - ''; - body = '' - The Consortium behind the Fediversity project announces that the project has officially been started. NLnet, Tweag, NorduNet and the Open Internet Discourse Foundation are working together to build a new service for cloud hosters. + collections.news.entry = + { link, ... }: + { + title = "Fediversity project publicly announced"; + description = "The Fediversity project has officially been announced"; + date = "2024-01-01"; + author = "Laurens Hof"; + summary = '' + We are pleased to introduce the launch of our new website dedicated to the Fediversity project. + ''; + body = '' + The Consortium behind the Fediversity project announces that the project has officially been started. NLnet, Tweag, NorduNet and the Open Internet Discourse Foundation are working together to build a new service for cloud hosters. - Fediversity is a comprehensive effort to bring easy-to-use, hosted cloud services with service portability and personal freedom at their core to everyone. It wants to provide everyone with high-quality, secure IT systems for everyday use. Without tracking, without exploitation, in a way that runs everywhere and scales effortlessly. Fediversity is based on NixOS, a disruptive Linux distribution with a unique approach to package and configuration management. Built on top of the Nix package manager, NixOS is completely declarative, makes upgrading systems reliable, and has many other advantages. Because it is reproducible, it is ideally suited for complex deployment scenario's where consistent behaviour, stability and configurability matter. + Fediversity is a comprehensive effort to bring easy-to-use, hosted cloud services with service portability and personal freedom at their core to everyone. It wants to provide everyone with high-quality, secure IT systems for everyday use. Without tracking, without exploitation, in a way that runs everywhere and scales effortlessly. Fediversity is based on NixOS, a disruptive Linux distribution with a unique approach to package and configuration management. Built on top of the Nix package manager, NixOS is completely declarative, makes upgrading systems reliable, and has many other advantages. Because it is reproducible, it is ideally suited for complex deployment scenario's where consistent behaviour, stability and configurability matter. - Fediversity has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement No. 101136078. - ''; - }; + Fediversity has received funding from the European Union’s Horizon Europe research and innovation programme under grant agreement No. 101136078. + ''; + }; } diff --git a/website/default.nix b/website/default.nix index f68ec04..258d1ff 100644 --- a/website/default.nix +++ b/website/default.nix @@ -1,14 +1,16 @@ -{ sources ? import ../npins -, system ? builtins.currentSystem -, pkgs ? import sources.nixpkgs { +{ + sources ? import ../npins, + system ? builtins.currentSystem, + pkgs ? import sources.nixpkgs { inherit system; config = { }; overlays = [ ]; - } -, lib ? import "${sources.nixpkgs}/lib" + }, + lib ? import "${sources.nixpkgs}/lib", }: let - lib' = final: prev: + lib' = + final: prev: let new = import ./lib.nix { lib = final; }; in @@ -37,15 +39,21 @@ rec { let run-tests = pkgs.writeShellApplication { name = "run-tests"; - text = with pkgs; with lib; '' - ${getExe nix-unit} ${toString ./tests.nix} "$@" - ''; + text = + with pkgs; + with lib; + '' + ${getExe nix-unit} ${toString ./tests.nix} "$@" + ''; }; test-loop = pkgs.writeShellApplication { name = "test-loop"; - text = with pkgs; with lib; '' - ${getExe watchexec} -w ${toString ./.} -- ${getExe nix-unit} ${toString ./tests.nix} - ''; + text = + with pkgs; + with lib; + '' + ${getExe watchexec} -w ${toString ./.} -- ${getExe nix-unit} ${toString ./tests.nix} + ''; }; devmode = pkgs.devmode.override { buildArgs = "${toString ./.} -A build --show-trace"; @@ -62,7 +70,9 @@ rec { }; inherit sources pkgs; - tests = with pkgs; with lib; + tests = + with pkgs; + with lib; let source = fileset.toSource { root = ../.; diff --git a/website/lib.nix b/website/lib.nix index 148c1da..f18adf2 100644 --- a/website/lib.nix +++ b/website/lib.nix @@ -1,21 +1,25 @@ { lib }: rec { - template = g: f: x: + template = + g: f: x: let base = f x; result = g base; in - result // { - override = new: + result + // { + override = + new: let base' = - if lib.isFunction new - then lib.recursiveUpdate base (new base' base) + if lib.isFunction new then + lib.recursiveUpdate base (new base' base) else lib.recursiveUpdate base new; result' = g base'; in - result' // { + result' + // { override = new: (template g (x': base') x).override new; }; }; @@ -28,7 +32,8 @@ rec { replaceStringRec "--" "-" "hello-----world" => "hello-world" */ - replaceStringsRec = from: to: string: + replaceStringsRec = + from: to: string: let replaced = lib.replaceStrings [ from ] [ to ] string; in @@ -37,25 +42,24 @@ rec { /** Create a URL-safe slug from any string */ - slug = str: + slug = + str: let # Replace non-alphanumeric characters with hyphens - replaced = join "" - ( - builtins.map - (c: - if (c >= "a" && c <= "z") || (c >= "0" && c <= "9") - then c - else "-" - ) - (with lib; stringToCharacters (toLower str))); + replaced = join "" ( + builtins.map (c: if (c >= "a" && c <= "z") || (c >= "0" && c <= "9") then c else "-") ( + with lib; stringToCharacters (toLower str) + ) + ); # Remove leading and trailing hyphens - trimHyphens = s: + trimHyphens = + s: let matched = builtins.match "(-*)([^-].*[^-]|[^-])(-*)" s; in - with lib; optionalString (!isNull matched) (builtins.elemAt matched 1); + with lib; + optionalString (!isNull matched) (builtins.elemAt matched 1); in trimHyphens (replaceStringsRec "--" "-" replaced); @@ -64,9 +68,11 @@ rec { /** Trim trailing spaces and squash non-leading spaces */ - trim = string: + trim = + string: let - trimLine = line: + trimLine = + line: with lib; let # separate leading spaces from the rest @@ -76,8 +82,7 @@ rec { # drop trailing spaces body = head (split " *$" rest); in - if body == "" then "" else - spaces + replaceStringsRec " " " " body; + if body == "" then "" else spaces + replaceStringsRec " " " " body; in join "\n" (map trimLine (splitLines string)); @@ -85,84 +90,95 @@ rec { splitLines = s: with builtins; filter (x: !isList x) (split "\n" s); - indent = prefix: s: + indent = + prefix: s: with lib.lists; let lines = splitLines s; in - join "\n" ( - [ (head lines) ] - ++ - (map (x: if x == "" then x else "${prefix}${x}") (tail lines)) - ); + join "\n" ([ (head lines) ] ++ (map (x: if x == "" then x else "${prefix}${x}") (tail lines))); - relativePath = path1': path2': + relativePath = + path1': path2': let inherit (lib.path) subpath; - inherit (lib) lists length take drop min max; + inherit (lib) + lists + length + take + drop + min + max + ; path1 = subpath.components path1'; prefix1 = take (length path1 - 1) path1; path2 = subpath.components path2'; prefix2 = take (length path2 - 1) path2; - commonPrefixLength = with lists; - findFirstIndex (i: i.fst != i.snd) - (min (length prefix1) (length prefix2)) - (zipLists prefix1 prefix2); + commonPrefixLength = + with lists; + findFirstIndex (i: i.fst != i.snd) (min (length prefix1) (length prefix2)) ( + zipLists prefix1 prefix2 + ); depth = max 0 (length prefix1 - commonPrefixLength); - relativeComponents = with lists; + relativeComponents = + with lists; [ "." ] ++ (replicate depth "..") ++ (drop commonPrefixLength path2); in join "/" relativeComponents; /** - Recursively list all Nix files from a directory, except the top-level `default.nix` + Recursively list all Nix files from a directory, except the top-level `default.nix` - Useful for module system `imports` from a top-level module. - **/ - nixFiles = dir: with lib.fileset; - toList (difference - (fileFilter ({ hasExt, ... }: hasExt "nix") dir) - (dir + "/default.nix") - ); + Useful for module system `imports` from a top-level module. + * + */ + nixFiles = + dir: + with lib.fileset; + toList (difference (fileFilter ({ hasExt, ... }: hasExt "nix") dir) (dir + "/default.nix")); types = rec { # arbitrarily nested attribute set where the leaves are of type `type` # NOTE: this works for anything but attribute sets! - recursiveAttrs = type: with lib.types; + recursiveAttrs = + type: + with lib.types; # NOTE: due to how `either` works, the first match is significant, # so if `type` happens to be an attrset, the typecheck will consider # `type`, not `attrsOf` attrsOf (either type (recursiveAttrs type)); # collection of unnamed items that can be added to item-wise, i.e. without wrapping the item in a list - collection = elemType: + collection = + elemType: let unparenthesize = class: class == "noun"; - desc = type: - types.optionDescriptionPhrase unparenthesize type; - desc' = type: + desc = type: types.optionDescriptionPhrase unparenthesize type; + desc' = + type: let typeDesc = lib.types.optionDescriptionPhrase unparenthesize type; in - if type.descriptionClass == "noun" - then - typeDesc + "s" - else - "many instances of ${typeDesc}"; + if type.descriptionClass == "noun" then typeDesc + "s" else "many instances of ${typeDesc}"; in lib.types.mkOptionType { name = "collection"; description = "separately specified ${desc elemType} for a collection of ${desc' elemType}"; - merge = loc: defs: - map - (def: - elemType.merge (loc ++ [ "[definition ${toString def.file}]" ]) [{ inherit (def) file; value = def.value; }] - ) - defs; + merge = + loc: defs: + map ( + def: + elemType.merge (loc ++ [ "[definition ${toString def.file}]" ]) [ + { + inherit (def) file; + value = def.value; + } + ] + ) defs; check = elemType.check; getSubOptions = elemType.getSubOptions; getSubModules = elemType.getSubModules; @@ -175,29 +191,34 @@ rec { nestedTypes.elemType = elemType; }; - listOfUnique = elemType: + listOfUnique = + elemType: let baseType = lib.types.listOf elemType; in - baseType // { - merge = loc: defs: + 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; + 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; + 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; }; diff --git a/website/presentation/default.nix b/website/presentation/default.nix index a0d679e..8a20230 100644 --- a/website/presentation/default.nix +++ b/website/presentation/default.nix @@ -1,4 +1,10 @@ -{ config, options, lib, pkgs, ... }: +{ + config, + options, + lib, + pkgs, + ... +}: let inherit (lib) mkOption @@ -8,13 +14,12 @@ in { imports = lib.nixFiles ./.; - options.templates = - mkOption { - description = '' - Collection of named helper functions for conversion different structured representations which can be rendered to a string - ''; - type = with types; recursiveAttrs (functionTo (either str attrs)); - }; + options.templates = mkOption { + description = '' + Collection of named helper functions for conversion different structured representations which can be rendered to a string + ''; + type = with types; recursiveAttrs (functionTo (either str attrs)); + }; options.files = mkOption { description = '' @@ -32,58 +37,64 @@ in type = types.package; default = let - script = '' - mkdir $out - '' + lib.join "\n" copy; - copy = lib.mapAttrsToList - ( - path: file: '' - mkdir -p $out/$(dirname ${path}) - cp -r ${file} $out/${path} - '' - ) - config.files; + script = + '' + mkdir $out + '' + + lib.join "\n" copy; + copy = lib.mapAttrsToList (path: file: '' + mkdir -p $out/$(dirname ${path}) + cp -r ${file} $out/${path} + '') config.files; in pkgs.runCommand "source" { } script; }; # TODO: this is an artefact of exploration; needs to be adapted to actual use - config.templates.table-of-contents = { config, ... }: + config.templates.table-of-contents = + { config, ... }: let - outline = { ... }: { - options = { - value = mkOption { - # null denotes root - type = with types; nullOr (either str (listOf (attrTag categories.phrasing))); - subsections = mkOption { - type = with types; listOf (submodule outline); - default = with lib; map - # TODO: go into depth manually here, - # we don't want to pollute the DOM implementation - (c: (lib.head (attrValues c)).outline) - (filter (c: isAttrs c && (lib.head (attrValues c)) ? outline) config.content); + outline = + { ... }: + { + options = { + value = mkOption { + # null denotes root + type = with types; nullOr (either str (listOf (attrTag categories.phrasing))); + subsections = mkOption { + type = with types; listOf (submodule outline); + default = + with lib; + map + # TODO: go into depth manually here, + # we don't want to pollute the DOM implementation + (c: (lib.head (attrValues c)).outline) + (filter (c: isAttrs c && (lib.head (attrValues c)) ? outline) config.content); + }; + }; + __toString = mkOption { + type = with types; functionTo str; + # TODO: convert to HTML + default = + self: + lib.squash '' + ${if isNull self.value then "root" else self.value} + ${if self.subsections != [ ] then " " + lib.indent " " (lib.join "\n" self.subsections) else ""} + ''; }; }; - __toString = mkOption { - type = with types; functionTo str; - # TODO: convert to HTML - default = self: lib.squash '' - ${if isNull self.value then "root" else self.value} - ${if self.subsections != [] then - " " + lib.indent " " (lib.join "\n" self.subsections) else ""} - ''; - }; }; - }; in { options.outline = mkOption { type = types.submodule outline; default = { value = null; - subsections = with lib; - map (c: (lib.head (attrValues c)).outline) - (filter (c: isAttrs c && (lib.head (attrValues c)) ? outline) config.content); + subsections = + with lib; + map (c: (lib.head (attrValues c)).outline) ( + filter (c: isAttrs c && (lib.head (attrValues c)) ? outline) config.content + ); }; }; }; diff --git a/website/presentation/dom.nix b/website/presentation/dom.nix index 1c06780..0911a7a 100644 --- a/website/presentation/dom.nix +++ b/website/presentation/dom.nix @@ -28,36 +28,46 @@ let ]; # base type for all DOM elements - element = { ... }: { - # TODO: add fields for upstream documentation references - # TODO: programmatically generate documentation - options = with lib; { - categories = mkOption { - type = types.listOfUnique (types.enum content-categories); - }; - __toString = mkOption { - internal = true; - type = with types; functionTo str; + element = + { ... }: + { + # TODO: add fields for upstream documentation references + # TODO: programmatically generate documentation + options = with lib; { + categories = mkOption { + type = types.listOfUnique (types.enum content-categories); + }; + __toString = mkOption { + internal = true; + type = with types; functionTo str; + }; }; }; - }; # options with types for all the defined DOM elements - element-types = lib.mapAttrs - (name: value: mkOption { type = submodule value; }) - elements; + element-types = lib.mapAttrs (name: value: mkOption { type = submodule value; }) elements; # attrset of categories, where values are module options with the type of the # elements that belong to these categories - categories = with lib; - genAttrs - content-categories - (category: - (mapAttrs (_: e: mkOption { type = submodule e; }) - # HACK: don't evaluate the submodule types, just grab the config directly - # TODO: we may want to do this properly and loop `categories` through the top-level `config` - (filterAttrs (_: e: elem category (e { name = "dummy"; config = { }; }).config.categories) elements)) - ); + categories = + with lib; + genAttrs content-categories ( + category: + (mapAttrs (_: e: mkOption { type = submodule e; }) + # HACK: don't evaluate the submodule types, just grab the config directly + # TODO: we may want to do this properly and loop `categories` through the top-level `config` + ( + filterAttrs ( + _: e: + elem category + (e { + name = "dummy"; + config = { }; + }).config.categories + ) elements + ) + ) + ); global-attrs = lib.mapAttrs (name: value: mkOption value) { class = { @@ -131,7 +141,8 @@ let # https://html.spec.whatwg.org/multipage/document-sequences.html#valid-navigable-target-name-or-keyword type = let - is-valid-target = s: + is-valid-target = + s: let inherit (lib) match; has-lt = s: match ".*<.*" s != null; @@ -140,14 +151,19 @@ let in has-valid-start s && !(has-lt s && has-tab-or-newline s); in - with types; either - (enum [ "_blank" "_self" "_parent" "_top" ]) - (types.addCheck str is-valid-target) - ; + with types; + either (enum [ + "_blank" + "_self" + "_parent" + "_top" + ]) (types.addCheck str is-valid-target); }; }; - mkAttrs = attrs: with lib; + mkAttrs = + attrs: + with lib; mkOption { type = submodule { options = global-attrs // attrs; @@ -155,28 +171,33 @@ let default = { }; }; - print-attrs = with lib; attrs: + print-attrs = + with lib; + attrs: # TODO: figure out how let attributes know how to print themselves without polluting the interface let - result = trim (join " " - (mapAttrsToList - # TODO: this needs to be smarter for boolean attributes - # where the value must be written out explicitly. - # probably the attribute itself should have its own `__toString`. - (name: value: - if isBool value then - if value then name else "" - # TODO: some attributes must be explicitly empty - else optionalString (toString value != "") ''${name}="${toString value}"'' - ) - attrs) + result = trim ( + join " " ( + mapAttrsToList + # TODO: this needs to be smarter for boolean attributes + # where the value must be written out explicitly. + # probably the attribute itself should have its own `__toString`. + ( + name: value: + if isBool value then + if value then name else "" + # TODO: some attributes must be explicitly empty + else + optionalString (toString value != "") ''${name}="${toString value}"'' + ) + attrs + ) ); in - if attrs == null then throw "wat" else - optionalString (stringLength result > 0) " " + result - ; + if attrs == null then throw "wat" else optionalString (stringLength result > 0) " " + result; - print-element = name: attrs: content: + print-element = + name: attrs: content: with lib; # TODO: be smarter about content to save some space and repetition at the call sites squash (trim '' @@ -187,472 +208,575 @@ let print-element' = name: attrs: "<${name}${print-attrs attrs}>"; - toString-unwrap = e: + toString-unwrap = + e: with lib; - if isAttrs e - then toString (head (attrValues e)) - else if isList e - then toString (map toString-unwrap e) - else e; + if isAttrs e then + toString (head (attrValues e)) + else if isList e then + toString (map toString-unwrap e) + else + e; elements = rec { - document = { ... }: { - imports = [ element ]; - options = { - inherit (element-types) html; - attrs = mkAttrs { }; - }; - - config.categories = [ ]; - config.__toString = self: '' - - ${self.html} - ''; - }; - - html = { name, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - inherit (element-types) head body; - }; - - config.categories = [ ]; - config.__toString = self: print-element name self.attrs '' - ${self.head} - ${self.body} - ''; - }; - - head = { name, ... }: { - imports = [ element ]; - options = with lib; { - attrs = mkAttrs { }; - # https://html.spec.whatwg.org/multipage/semantics.html#the-head-element:concept-element-content-model - # XXX: this doesn't implement the iframe srcdoc semantics - # as those have questionable value and would complicate things a bit. - # it should be possible though, by passing a flag via module arguments. - inherit (element-types) title; - base = mkOption { - type = with types; nullOr (submodule base); - default = null; - }; - # https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-charset - meta.charset = mkOption { - # TODO: create programmatically from https://encoding.spec.whatwg.org/encodings.json - type = types.enum [ - "utf-8" - ]; - default = "utf-8"; - }; - # https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#viewport_width_and_screen_width - # this should not exist and no one should ever have to think about it - meta.viewport = mkOption { - type = submodule ({ ... }: { - # TODO: figure out how to render only non-default values - options = { - width = mkOption { - type = with types; either - (ints.between 1 10000) - (enum [ "device-width" ]); - default = "device-width"; # not default by standard - }; - height = mkOption { - type = with types; either - (ints.between 1 10000) - (enum [ "device-height" ]); - default = "device-height"; # not default by standard (but seems to work if you don't set it) - }; - initial-scale = mkOption { - type = types.numbers.between 0.1 10; - default = 1; - }; - minimum-scale = mkOption { - type = types.numbers.between 0.1 10; - # TODO: render only as many digits as needed - default = 0.1; - }; - maximum-scale = mkOption { - type = types.numbers.between 0.1 10; - default = 10; - }; - user-scalable = mkOption { - type = types.bool; - default = true; - }; - interactive-widget = mkOption { - type = types.enum [ - "resizes-visual" - "resizes-content" - "overlays-content" - ]; - default = "resizes-visual"; - }; - }; - }); - default = { }; + document = + { ... }: + { + imports = [ element ]; + options = { + inherit (element-types) html; + attrs = mkAttrs { }; }; - meta.authors = mkOption { - type = with types; listOf str; - default = [ ]; - }; - meta.description = mkOption { - type = with types; nullOr str; - default = null; - }; - # TODO: this one has more internal structure, e.g with hreflang - # TODO: print in output - link.canonical = mkOption { - type = with types; nullOr str; - default = null; - }; - link.stylesheets = mkOption { - type = types.listOf (submodule stylesheet); - default = [ ]; - }; - - # TODO: figure out `meta` elements - # https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element:concept-element-attributes - # https://html.spec.whatwg.org/multipage/semantics.html#other-metadata-names - }; - - config.categories = [ ]; - config.__toString = self: - with lib; - print-element name self.attrs '' - ${self.title} - ${with lib; optionalString (!isNull self.base) self.base} - - - ${/* https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-x-ua-compatible */ - ""} - - - - - - ${print-element' "meta" { - name = "viewport"; - content = "${join ", " (mapAttrsToList (name: value: "${name}=${toString value}") self.meta.viewport) }"; - }} - - ${join "\n" (map - (author: print-element' "meta" { - name = "author"; - content = "${author}"; - }) - self.meta.authors) - } - - ${join "\n" (map - (stylesheet: print-element' "link" ({ rel = "stylesheet"; } // (removeAttrs stylesheet [ "categories" "__toString" ]))) - self.link.stylesheets) - } + config.categories = [ ]; + config.__toString = self: '' + + ${self.html} ''; - }; - - title = { name, ... }: { - imports = [ element ]; - options.attrs = mkAttrs { }; - options.text = mkOption { - type = types.str; }; - config.categories = [ "metadata" ]; - config.__toString = self: "<${name}${print-attrs self.attrs}>${self.text}"; - }; - - base = { name, ... }: { - imports = [ element ]; - # TODO: "A base element must have either an href attribute, a target attribute, or both." - options = global-attrs // { inherit (attrs) href target; }; - config.categories = [ "metadata" ]; - config.__toString = self: ""; - }; - - link = { name, ... }: { - imports = [ element ]; - options = global-attrs // { - # TODO: more attributes - # https://html.spec.whatwg.org/multipage/semantics.html#the-link-element:concept-element-attributes - inherit (attrs) href; - # XXX: there are variants of `rel` for `link`, `a`/`area`, and `form` - rel = mkOption { - # https://html.spec.whatwg.org/multipage/semantics.html#attr-link-rel - type = with types; listOfUnique str (enum - # TODO: work out link types in detail, there are lots of additional constraints - # https://html.spec.whatwg.org/multipage/links.html#linkTypes - [ - "alternate" - "dns-prefetch" - "expect" - "help" - "icon" - "license" - "manifest" - "modulepreload" - "next" - "pingback" - "preconnect" - "prefetch" - "preload" - "prev" - "privacy-policy" - "search" - "terms-of-service" - ] - ); + html = + { name, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + inherit (element-types) head body; }; + + config.categories = [ ]; + config.__toString = + self: + print-element name self.attrs '' + ${self.head} + ${self.body} + ''; + }; + + head = + { name, ... }: + { + imports = [ element ]; + options = with lib; { + attrs = mkAttrs { }; + # https://html.spec.whatwg.org/multipage/semantics.html#the-head-element:concept-element-content-model + # XXX: this doesn't implement the iframe srcdoc semantics + # as those have questionable value and would complicate things a bit. + # it should be possible though, by passing a flag via module arguments. + inherit (element-types) title; + base = mkOption { + type = with types; nullOr (submodule base); + default = null; + }; + # https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-charset + meta.charset = mkOption { + # TODO: create programmatically from https://encoding.spec.whatwg.org/encodings.json + type = types.enum [ + "utf-8" + ]; + default = "utf-8"; + }; + # https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag#viewport_width_and_screen_width + # this should not exist and no one should ever have to think about it + meta.viewport = mkOption { + type = submodule ( + { ... }: + { + # TODO: figure out how to render only non-default values + options = { + width = mkOption { + type = with types; either (ints.between 1 10000) (enum [ "device-width" ]); + default = "device-width"; # not default by standard + }; + height = mkOption { + type = with types; either (ints.between 1 10000) (enum [ "device-height" ]); + default = "device-height"; # not default by standard (but seems to work if you don't set it) + }; + initial-scale = mkOption { + type = types.numbers.between 0.1 10; + default = 1; + }; + minimum-scale = mkOption { + type = types.numbers.between 0.1 10; + # TODO: render only as many digits as needed + default = 0.1; + }; + maximum-scale = mkOption { + type = types.numbers.between 0.1 10; + default = 10; + }; + user-scalable = mkOption { + type = types.bool; + default = true; + }; + interactive-widget = mkOption { + type = types.enum [ + "resizes-visual" + "resizes-content" + "overlays-content" + ]; + default = "resizes-visual"; + }; + }; + } + ); + default = { }; + }; + + meta.authors = mkOption { + type = with types; listOf str; + default = [ ]; + }; + meta.description = mkOption { + type = with types; nullOr str; + default = null; + }; + # TODO: this one has more internal structure, e.g with hreflang + # TODO: print in output + link.canonical = mkOption { + type = with types; nullOr str; + default = null; + }; + link.stylesheets = mkOption { + type = types.listOf (submodule stylesheet); + default = [ ]; + }; + + # TODO: figure out `meta` elements + # https://html.spec.whatwg.org/multipage/semantics.html#the-meta-element:concept-element-attributes + # https://html.spec.whatwg.org/multipage/semantics.html#other-metadata-names + }; + + config.categories = [ ]; + config.__toString = + self: + with lib; + print-element name self.attrs '' + ${self.title} + ${with lib; optionalString (!isNull self.base) self.base} + + + ${ + # https://html.spec.whatwg.org/multipage/semantics.html#attr-meta-http-equiv-x-ua-compatible + "" + } + + + + + + ${print-element' "meta" { + name = "viewport"; + content = "${join ", " ( + mapAttrsToList (name: value: "${name}=${toString value}") self.meta.viewport + )}"; + }} + + ${join "\n" ( + map ( + author: + print-element' "meta" { + name = "author"; + content = "${author}"; + } + ) self.meta.authors + )} + + ${join "\n" ( + map ( + stylesheet: + print-element' "link" ( + { + rel = "stylesheet"; + } + // (removeAttrs stylesheet [ + "categories" + "__toString" + ]) + ) + ) self.link.stylesheets + )} + ''; + }; + + title = + { name, ... }: + { + imports = [ element ]; + options.attrs = mkAttrs { }; + options.text = mkOption { + type = types.str; + }; + config.categories = [ "metadata" ]; + config.__toString = self: "<${name}${print-attrs self.attrs}>${self.text}"; + + }; + + base = + { name, ... }: + { + imports = [ element ]; + # TODO: "A base element must have either an href attribute, a target attribute, or both." + options = global-attrs // { + inherit (attrs) href target; + }; + config.categories = [ "metadata" ]; + config.__toString = self: ""; + }; + + link = + { name, ... }: + { + imports = [ element ]; + options = global-attrs // { + # TODO: more attributes + # https://html.spec.whatwg.org/multipage/semantics.html#the-link-element:concept-element-attributes + inherit (attrs) href; + # XXX: there are variants of `rel` for `link`, `a`/`area`, and `form` + rel = mkOption { + # https://html.spec.whatwg.org/multipage/semantics.html#attr-link-rel + type = + with types; + listOfUnique str (enum + # TODO: work out link types in detail, there are lots of additional constraints + # https://html.spec.whatwg.org/multipage/links.html#linkTypes + [ + "alternate" + "dns-prefetch" + "expect" + "help" + "icon" + "license" + "manifest" + "modulepreload" + "next" + "pingback" + "preconnect" + "prefetch" + "preload" + "prev" + "privacy-policy" + "search" + "terms-of-service" + ]); + }; + }; + # TODO: figure out how to make body-ok `link` elements + # https://html.spec.whatwg.org/multipage/semantics.html#allowed-in-the-body + config.categories = [ "metadata" ]; + config.__toString = self: ""; }; - # TODO: figure out how to make body-ok `link` elements - # https://html.spec.whatwg.org/multipage/semantics.html#allowed-in-the-body - config.categories = [ "metadata" ]; - config.__toString = self: ""; - }; # is implemented separately because it can be used both in `` and `` # semantically it's a standalone thing but syntactically happens to be subsumed under `` - stylesheet = { config, name, ... }: { - imports = [ element ]; - options = global-attrs // { - type = mkOption { - # TODO: this must be a valid MIME type string, which is a bit involved. - # the syntax is explicated here: https://mimesniff.spec.whatwg.org/#mime-type-writing - # but the spec refers to RFC9110: https://www.rfc-editor.org/rfc/rfc9110#name-media-type - # all registered MIME types: https://www.iana.org/assignments/top-level-media-types/top-level-media-types.xhtml - # XXX: if nothing is specified, "text/css" is assumed. - # https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:link-type-stylesheet-2 - # there's no specification on what else could be there, and it's questionable whether setting anything else even makes sense. - # in practice, browsers seem to ignore anything but "text/css", so we may as well not care at all. - type = with types; nullOr str; - default = null; + stylesheet = + { config, name, ... }: + { + imports = [ element ]; + options = global-attrs // { + type = mkOption { + # TODO: this must be a valid MIME type string, which is a bit involved. + # the syntax is explicated here: https://mimesniff.spec.whatwg.org/#mime-type-writing + # but the spec refers to RFC9110: https://www.rfc-editor.org/rfc/rfc9110#name-media-type + # all registered MIME types: https://www.iana.org/assignments/top-level-media-types/top-level-media-types.xhtml + # XXX: if nothing is specified, "text/css" is assumed. + # https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:link-type-stylesheet-2 + # there's no specification on what else could be there, and it's questionable whether setting anything else even makes sense. + # in practice, browsers seem to ignore anything but "text/css", so we may as well not care at all. + type = with types; nullOr str; + default = null; + }; + # https://html.spec.whatwg.org/multipage/semantics.html#attr-link-disabled + disabled = mkOption { + type = types.bool; + default = false; + }; + # TODO: implement the rest of the stylesheet attributes + # https://html.spec.whatwg.org/#link-type-stylesheet + inherit (link-attrs) href media integrity; }; - # https://html.spec.whatwg.org/multipage/semantics.html#attr-link-disabled - disabled = mkOption { - type = types.bool; - default = false; - }; - # TODO: implement the rest of the stylesheet attributes - # https://html.spec.whatwg.org/#link-type-stylesheet - inherit (link-attrs) href media integrity; + # https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:body-ok + config.categories = [ + "metadata" + "phrasing" + ]; + config.__toString = + self: + print-attrs ( + removeAttrs self [ + "categories" + "__toString" + ] + ); }; - # https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:body-ok - config.categories = [ "metadata" "phrasing" ]; - config.__toString = self: print-attrs (removeAttrs self [ "categories" "__toString" ]); - }; - body = { config, name, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - content = mkOption { - type = with types; - let - # Type check that ensures spec-compliant section hierarchy - # https://html.spec.whatwg.org/multipage/sections.html#headings-and-outlines-2:concept-heading-7 - with-section-constraints = baseType: baseType // { - merge = loc: defs: - with lib; - let - find-and-attach = def: + body = + { config, name, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + content = mkOption { + type = + with types; + let + # Type check that ensures spec-compliant section hierarchy + # https://html.spec.whatwg.org/multipage/sections.html#headings-and-outlines-2:concept-heading-7 + with-section-constraints = + baseType: + baseType + // { + merge = + loc: defs: + with lib; let - process-with-depth = depth: content: - map - (x: - if isAttrs x && x ? section - then x // { - section = x.section // { - heading-level = depth; - content = process-with-depth (depth + 1) (x.section.content or [ ]); - }; - } - else x - ) - content; - - find-with-depth = depth: content: + find-and-attach = + def: let - sections = map (v: { inherit (def) file; value = v; depth = depth; }) - (filter (x: isAttrs x && x ? section) content); - subsections = concatMap - (x: - if isAttrs x && x ? section && x.section ? content - then find-with-depth (depth + 1) x.section.content - else [ ]) - content; + process-with-depth = + depth: content: + map ( + x: + if isAttrs x && x ? section then + x + // { + section = x.section // { + heading-level = depth; + content = process-with-depth (depth + 1) (x.section.content or [ ]); + }; + } + else + x + ) content; + + find-with-depth = + depth: content: + let + sections = map (v: { + inherit (def) file; + value = v; + depth = depth; + }) (filter (x: isAttrs x && x ? section) content); + subsections = concatMap ( + x: + if isAttrs x && x ? section && x.section ? content then + find-with-depth (depth + 1) x.section.content + else + [ ] + ) content; + in + sections ++ subsections; + in - sections ++ subsections; + { + inherit def; + processed = process-with-depth 1 def.value; + validation = find-with-depth 1 def.value; + }; + processed = map find-and-attach defs; + all-sections = flatten (map (p: p.validation) processed); + too-deep = filter (sec: sec.depth > 6) all-sections; in - { - inherit def; - processed = process-with-depth 1 def.value; - validation = find-with-depth 1 def.value; - }; + if too-deep != [ ] then + throw '' + The option `${lib.options.showOption loc}` has sections nested too deeply: + ${concatMapStrings ( + sec: " - depth ${toString sec.depth} section in ${toString sec.file}\n" + ) too-deep} + Section hierarchy must not be deeper than 6 levels.'' + else + baseType.merge loc (map (p: p.def // { value = p.processed; }) processed); + }; + in + with-section-constraints + # TODO: find a reasonable cut-off for where to place raw content + (listOf (either str (attrTag categories.flow))); + default = [ ]; + }; + }; - processed = map find-and-attach defs; - all-sections = flatten (map (p: p.validation) processed); - too-deep = filter (sec: sec.depth > 6) all-sections; - in - if too-deep != [ ] then - throw '' - The option `${lib.options.showOption loc}` has sections nested too deeply: - ${concatMapStrings (sec: " - depth ${toString sec.depth} section in ${toString sec.file}\n") too-deep} - Section hierarchy must not be deeper than 6 levels.'' - else baseType.merge loc (map (p: p.def // { value = p.processed; }) processed); - }; + config.categories = [ ]; + config.__toString = + self: with lib; print-element name self.attrs (join "\n" (map toString-unwrap self.content)); + }; + + section = + { config, name, ... }: + { + imports = [ element ]; + options = { + # setting to an attribute set will wrap the section in `
` + attrs = mkOption { + type = + with types; + nullOr (submodule { + options = global-attrs; + }); + default = null; + }; + heading = mkOption { + # XXX: while there are no explicit rules on whether sections should contain headers, + # sections should have content that would be listed in an outline. + # + # https://html.spec.whatwg.org/multipage/sections.html#use-div-for-wrappers + # + # such an outline is rather meaningless without headings for navigation, + # which is why we enforce headings in sections. + # arguably, and this is encoded here, a section *is defined* by its heading. + type = + with types; + submodule ( + { config, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + # setting to an attribute set will wrap the section in `
` + hgroup.attrs = mkOption { + type = + with types; + nullOr (submodule { + options = global-attrs; + }); + default = with lib; if (config.before == [ ] && config.after == [ ]) then null else { }; + }; + # https://html.spec.whatwg.org/multipage/sections.html#the-hgroup-element + before = mkOption { + type = with types; listOf (attrTag ({ inherit (element-types) p; } // categories.scripting)); + default = [ ]; + }; + content = mkOption { + # https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements + type = with types; either str (listOf (attrTag categories.phrasing)); + }; + after = mkOption { + type = with types; listOf (attrTag ({ inherit (element-types) p; } // categories.scripting)); + default = [ ]; + }; + }; + } + ); + }; + # https://html.spec.whatwg.org/multipage/sections.html#headings-and-outlines + content = mkOption { + type = with types; listOf (either str (attrTag categories.flow)); + default = [ ]; + }; + }; + options.heading-level = mkOption { + # XXX: this will proudly fail if the invariant is violated, + # but the error message will be inscrutable + type = with types; ints.between 1 6; + internal = true; + }; + config = { + categories = [ + "flow" + "sectioning" + "palpable" + ]; + __toString = + self: + with lib; + let + n = toString config.heading-level; + heading = ''${self.heading.content}''; + hgroup = + with lib; + print-element "hgroup" self.heading.hgroup.attrs (squash '' + ${optionalString (!isNull self.heading.before) (toString-unwrap self.heading.before)} + ${heading} + ${optionalString (!isNull self.heading.after) (toString-unwrap self.heading.after)} + ''); + content = + (if isNull self.heading.hgroup.attrs then heading else hgroup) + + join "\n" (map toString-unwrap self.content); in - with-section-constraints - # TODO: find a reasonable cut-off for where to place raw content - (listOf (either str (attrTag categories.flow))); - default = [ ]; + if !isNull self.attrs then print-element name self.attrs content else content; }; }; - config.categories = [ ]; - config.__toString = self: with lib; - print-element name self.attrs (join "\n" (map toString-unwrap self.content)); - }; + p = + { name, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + content = mkOption { + type = with types; either str (listOf (attrTag categories.phrasing)); + }; + }; + config.categories = [ + "flow" + "palpable" + ]; + config.__toString = self: print-element name self.attrs (toString self.content); + }; - section = { config, name, ... }: { - imports = [ element ]; - options = { - # setting to an attribute set will wrap the section in `
` - attrs = mkOption { - type = with types; nullOr (submodule { options = global-attrs; }); - default = null; + dl = + { config, name, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + content = mkOption { + type = + with types; + listOf ( + submodule ( + { ... }: + { + options = { + # TODO: wrap in `
` if set + div.attrs = mkOption { + type = + with types; + nullOr (submodule { + options = global-attrs; + }); + default = null; + }; + before = mkOption { + type = with types; listOf (attrTag categories.scripting); + default = [ ]; + }; + terms = mkOption { + type = with types; nonEmptyListOf (submodule dt); + }; + between = mkOption { + type = with types; listOf (attrTag categories.scripting); + default = [ ]; + }; + descriptions = mkOption { + type = with types; nonEmptyListOf (submodule dd); + }; + after = mkOption { + type = with types; listOf (attrTag categories.scripting); + default = [ ]; + }; + }; + } + ) + ); + }; }; - heading = mkOption { - # XXX: while there are no explicit rules on whether sections should contain headers, - # sections should have content that would be listed in an outline. - # - # https://html.spec.whatwg.org/multipage/sections.html#use-div-for-wrappers - # - # such an outline is rather meaningless without headings for navigation, - # which is why we enforce headings in sections. - # arguably, and this is encoded here, a section *is defined* by its heading. - type = with types; submodule ({ config, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - # setting to an attribute set will wrap the section in `
` - hgroup.attrs = mkOption { - type = with types; nullOr (submodule { options = global-attrs; }); - default = with lib; if (config.before == [ ] && config.after == [ ]) then null else { }; - }; - # https://html.spec.whatwg.org/multipage/sections.html#the-hgroup-element - before = mkOption { - type = with types; listOf (attrTag ({ inherit (element-types) p; } // categories.scripting)); - default = [ ]; - }; - content = mkOption { - # https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements - type = with types; either str (listOf (attrTag categories.phrasing)); - }; - after = mkOption { - type = with types; - listOf (attrTag ({ inherit (element-types) p; } // categories.scripting)); - default = [ ]; - }; - }; - }); - }; - # https://html.spec.whatwg.org/multipage/sections.html#headings-and-outlines - content = mkOption { - type = with types; listOf (either str (attrTag categories.flow)); - default = [ ]; - }; - }; - options.heading-level = mkOption { - # XXX: this will proudly fail if the invariant is violated, - # but the error message will be inscrutable - type = with types; ints.between 1 6; - internal = true; - }; - config = { - categories = [ "flow" "sectioning" "palpable" ]; - __toString = self: with lib; + # XXX: here we can't express the spec requirement that `dl` is palpable if the list of term-description-pairs is nonempty. + # the reason is that we have to specify a child's *type* in the parent, but being palpable is a property of the value in this case. + # and while the module system does have some dependent typing capabilities, we can't say "the type is X but only if its value has property Y". + # but since the "palpable" category isn't used in any structural requirement in the spec, this is not a loss of fidelity on our side. + # TODO: the whole notion of content categories may be a red herring for this implementation after all, reconsider it. + # it does help to concisely express type constraints on an element's children, but it seems that most of the categories in the spec can be ignored entirely in this implementation. + # the cleanup task would be to identify which categories are really helpful, and document the rationale for using that mechanism as well as the specific choice of categories to keep. + config.categories = [ "flow" ]; + config.__toString = + self: + with lib; let - n = toString config.heading-level; - heading = ''${self.heading.content}''; - hgroup = with lib; print-element "hgroup" self.heading.hgroup.attrs (squash '' - ${optionalString (!isNull self.heading.before) (toString-unwrap self.heading.before)} - ${heading} - ${optionalString (!isNull self.heading.after) (toString-unwrap self.heading.after)} - ''); - content = - (if isNull self.heading.hgroup.attrs then heading else hgroup) - + - join "\n" (map toString-unwrap self.content); - in - if !isNull self.attrs - then print-element name self.attrs content - else content; - }; - }; - - p = { name, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - content = mkOption { - type = with types; either str (listOf (attrTag categories.phrasing)); - }; - }; - config.categories = [ "flow" "palpable" ]; - config.__toString = self: print-element name self.attrs (toString self.content); - }; - - dl = { config, name, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - content = mkOption { - type = with types; listOf (submodule ({ ... }: { - options = { - # TODO: wrap in `
` if set - div.attrs = mkOption { - type = with types; nullOr (submodule { options = global-attrs; }); - default = null; - }; - before = mkOption { - type = with types; listOf (attrTag categories.scripting); - default = [ ]; - }; - terms = mkOption { - type = with types; nonEmptyListOf (submodule dt); - }; - between = mkOption { - type = with types; listOf (attrTag categories.scripting); - default = [ ]; - }; - descriptions = mkOption { - type = with types; nonEmptyListOf (submodule dd); - }; - after = mkOption { - type = with types; listOf (attrTag categories.scripting); - default = [ ]; - }; - }; - })); - }; - }; - # XXX: here we can't express the spec requirement that `dl` is palpable if the list of term-description-pairs is nonempty. - # the reason is that we have to specify a child's *type* in the parent, but being palpable is a property of the value in this case. - # and while the module system does have some dependent typing capabilities, we can't say "the type is X but only if its value has property Y". - # but since the "palpable" category isn't used in any structural requirement in the spec, this is not a loss of fidelity on our side. - # TODO: the whole notion of content categories may be a red herring for this implementation after all, reconsider it. - # it does help to concisely express type constraints on an element's children, but it seems that most of the categories in the spec can be ignored entirely in this implementation. - # the cleanup task would be to identify which categories are really helpful, and document the rationale for using that mechanism as well as the specific choice of categories to keep. - config.categories = [ "flow" ]; - config.__toString = self: - with lib; - let - content = map - (entry: + content = map ( + entry: let list = squash '' ${join "\n" entry.before} @@ -662,46 +786,63 @@ let ${join "\n" entry.after} ''; in - if !isNull entry.div.attrs - then print-element "div" entry.div.attrs list - else list - ) - self.content; - in - print-element name self.attrs (join "\n" content); - }; - - dt = { config, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - dt = mkOption { - type = with types; either str (submodule (attrTag ( - # TODO: test - with lib; removeAttrs - (filterAttrs - (name: value: ! any (c: elem c [ "sectioning" "heading" ]) value.categories) - categories.flow - ) - [ "header" "footer" ] - ))); - }; + if !isNull entry.div.attrs then print-element "div" entry.div.attrs list else list + ) self.content; + in + print-element name self.attrs (join "\n" content); }; - config.categories = [ ]; - config.__toString = self: print-element "dt" self.attrs self.dt; - }; - dd = { config, ... }: { - imports = [ element ]; - options = { - attrs = mkAttrs { }; - dd = mkOption { - type = with types; either str (submodule (attrTag categories.flow)); + dt = + { config, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + dt = mkOption { + type = + with types; + either str ( + submodule ( + attrTag ( + # TODO: test + with lib; + removeAttrs + (filterAttrs ( + name: value: + !any ( + c: + elem c [ + "sectioning" + "heading" + ] + ) value.categories + ) categories.flow) + [ + "header" + "footer" + ] + ) + ) + ); + }; }; + config.categories = [ ]; + config.__toString = self: print-element "dt" self.attrs self.dt; + }; + + dd = + { config, ... }: + { + imports = [ element ]; + options = { + attrs = mkAttrs { }; + dd = mkOption { + type = with types; either str (submodule (attrTag categories.flow)); + }; + }; + config.categories = [ ]; + config.__toString = self: print-element "dd" self.attrs self.dd; }; - config.categories = [ ]; - config.__toString = self: print-element "dd" self.attrs self.dd; - }; }; in { diff --git a/website/presentation/style.nix b/website/presentation/style.nix index 5f79fe5..df65ff3 100644 --- a/website/presentation/style.nix +++ b/website/presentation/style.nix @@ -1,27 +1,53 @@ -{ config, lib, pkgs, ... }: { +{ + config, + lib, + pkgs, + ... +}: +{ config.assets."style.css".path = ./style.css; config.assets."ngi-fediversity.svg".path = ./ngi-fediversity.svg; # TODO: auto-generate a bunch from SVG config.assets."favicon.png".path = ./favicon.png; - config.assets."fonts.css".path = with lib; builtins.toFile "fonts.css" (join "\n" (map - (font: '' - @font-face { - font-family: '${font.name}'; - font-style: normal; - font-weight: ${toString font.weight}; - src: url(/${head config.assets.${font.file}.locations}) format('woff2'); - } - '') - ( - (crossLists (name: file: weight: { inherit name file weight; }) - [ [ "Signika" ] [ "signika-extended.woff2" "signika.woff2" ] [ 500 700 ] ] + config.assets."fonts.css".path = + with lib; + builtins.toFile "fonts.css" ( + join "\n" ( + map + (font: '' + @font-face { + font-family: '${font.name}'; + font-style: normal; + font-weight: ${toString font.weight}; + src: url(/${head config.assets.${font.file}.locations}) format('woff2'); + } + '') + ( + (crossLists (name: file: weight: { inherit name file weight; }) [ + [ "Signika" ] + [ + "signika-extended.woff2" + "signika.woff2" + ] + [ + 500 + 700 + ] + ]) + ++ (crossLists (name: file: weight: { inherit name file weight; }) [ + [ "Heebo" ] + [ + "heebo-extended.woff2" + "heebo.woff2" + ] + [ + 400 + 600 + ] + ]) + ) ) - ++ - (crossLists (name: file: weight: { inherit name file weight; }) - [ [ "Heebo" ] [ "heebo-extended.woff2" "heebo.woff2" ] [ 400 600 ] ] - ) - ) - )); + ); # TODO: get directly from https://github.com/google/fonts # and compress with https://github.com/fonttools/fonttools diff --git a/website/presentation/templates.nix b/website/presentation/templates.nix index 34f6ce7..80422f9 100644 --- a/website/presentation/templates.nix +++ b/website/presentation/templates.nix @@ -1,4 +1,10 @@ -{ config, options, lib, pkgs, ... }: +{ + config, + options, + lib, + pkgs, + ... +}: let inherit (lib) mkOption @@ -7,11 +13,15 @@ let in { config.templates.html = { - dom = document: + dom = + document: let eval = lib.evalModules { class = "DOM"; - modules = [ document (import ./dom.nix) ]; + modules = [ + document + (import ./dom.nix) + ]; }; in { @@ -19,27 +29,34 @@ in value = eval.config; }; - markdown = { name, body }: + markdown = + { name, body }: let - commonmark = pkgs.runCommand "${name}.html" - { - buildInputs = [ pkgs.cmark ]; - } '' - cmark ${builtins.toFile "${name}.md" body} > $out - ''; + commonmark = + pkgs.runCommand "${name}.html" + { + buildInputs = [ pkgs.cmark ]; + } + '' + cmark ${builtins.toFile "${name}.md" body} > $out + ''; in builtins.readFile commonmark; - nav = { menu, page }: + nav = + { menu, page }: let - render-item = item: - if item ? menu then '' -
  • ${item.menu.label} - ${lib.indent " " (item.menu.outputs.html page)} -
  • - '' - else if item ? page then ''
  • ${item.page.title}
  • '' - else ''
  • ${item.link.label}
  • '' - ; + render-item = + item: + if item ? menu then + '' +
  • ${item.menu.label} + ${lib.indent " " (item.menu.outputs.html page)} +
  • + '' + else if item ? page then + ''
  • ${item.page.title}
  • '' + else + ''
  • ${item.link.label}
  • ''; in ''