diff --git a/users/sterni/machines/ingeborg/http/sterni.lv.nix b/users/sterni/machines/ingeborg/http/sterni.lv.nix
index 50c1bac29..cba56ce4f 100644
--- a/users/sterni/machines/ingeborg/http/sterni.lv.nix
+++ b/users/sterni/machines/ingeborg/http/sterni.lv.nix
@@ -3,7 +3,6 @@
let
inherit (depot.users.sterni.nix.html)
__findFile
- withDoctype
;
in
@@ -19,13 +18,13 @@ in
root = pkgs.writeTextFile {
name = "sterni.lv-http-root";
destination = "/index.html";
- text = withDoctype ( { } [
+ text = { } [
(
{ } [
( { charset = "utf-8"; } null)
( { } "no thoughts")
])
( { } "🦩")
- ]);
+ ];
};
# TODO(sterni): tmp.sterni.lv
locations."/tmp/".root = toString /srv/http;
diff --git a/users/sterni/nix/html/README.md b/users/sterni/nix/html/README.md
index 0349e466a..d636244c9 100644
--- a/users/sterni/nix/html/README.md
+++ b/users/sterni/nix/html/README.md
@@ -11,10 +11,10 @@ let
htmlNix = import ./path/to/html.nix { };
# make the magic work
- inherit (htmlNix) __findFile esc withDoctype;
+ inherit (htmlNix) __findFile esc;
in
-pkgs.writeText "example.html" (withDoctype ( {} [
+pkgs.writeText "example.html" ( {} [
( {} [
( { charset = "utf-8"; } null)
( {} (esc "hello world"))
@@ -35,7 +35,7 @@ pkgs.writeText "example.html" (withDoctype ( {} [
])
])
])
-]))
+])
```
Convince yourself it works:
diff --git a/users/sterni/nix/html/default.nix b/users/sterni/nix/html/default.nix
index 360fa7c47..9ffecc1d4 100644
--- a/users/sterni/nix/html/default.nix
+++ b/users/sterni/nix/html/default.nix
@@ -1,4 +1,4 @@
-# Copyright © 2021 sterni
+# SPDX-FileCopyrightText: Copyright © 2021, 2024 sterni
# SPDX-License-Identifier: MIT
#
# This file provides a cursed HTML DSL for nix which works by overloading
@@ -58,6 +58,9 @@ let
calls, we can't escape it automatically. Instead this must be done manually
using `esc`.
+ If the tag is "html", e.g. in case of ` { } …`, " will
+ be prepended to the normal rendering of the text.
+
Type: string -> attrs -> (list | string | null) -> string
Example:
@@ -98,20 +101,16 @@ let
then builtins.concatStringsSep "" (flatten content)
else content;
in
- if content == null
+ (if tag == "html" then "" else "") +
+ (if content == null
then "<${tag}${attrs'}/>"
- else "<${tag}${attrs'}>${content'}${tag}>";
+ else "<${tag}${attrs'}>${content'}${tag}>");
- /* Prepend "" to a string.
-
- Type: string -> string
-
- Example:
-
- withDoctype ( {} (esc "hello"))
- => "hello"
+ /* Deprecated, does nothing.
*/
- withDoctype = doc: "" + doc;
+ withDoctype = doc: builtins.trace
+ "WARN: withDoctype no longer does anything, ` { } [ … ]` takes care of rendering "
+ doc;
/* Taken from . */
flatten = x:
diff --git a/users/sterni/nix/html/tests/default.nix b/users/sterni/nix/html/tests/default.nix
index 17662f363..4c386f874 100644
--- a/users/sterni/nix/html/tests/default.nix
+++ b/users/sterni/nix/html/tests/default.nix
@@ -4,10 +4,9 @@ let
inherit (depot.users.sterni.nix.html)
__findFile
esc
- withDoctype
;
- exampleDocument = withDoctype ( { lang = "en"; } [
+ exampleDocument = { lang = "en"; } [
( { } [
( { charset = "utf-8"; } null)
( { } "html.nix example document")
@@ -78,7 +77,7 @@ let
])
])
])
- ]);
+ ];
in
pkgs.runCommand "html.nix.html"
diff --git a/users/tazjin/cursed/responder.nix b/users/tazjin/cursed/responder.nix
index 9aa6a2d55..9c1e29a20 100644
--- a/users/tazjin/cursed/responder.nix
+++ b/users/tazjin/cursed/responder.nix
@@ -4,7 +4,6 @@ let
inherit (depot.users.sterni.nix.html)
__findFile
esc
- withDoctype
;
# CGI envvars: https://www.instanet.com/cgi/env.html
@@ -24,7 +23,7 @@ let
default = let {
hasQuery = if builtins.length (builtins.attrNames query) > 0 then "?" else "";
- body = (withDoctype ( { lang = "en"; } [
+ body = { lang = "en"; } [
( { } [
( { } "some cursed nix")
])
@@ -33,7 +32,7 @@ let
( { } [ method " " path hasQuery rawQuery ])
(
{ } (builtins.toJSON query))
])
- ]));
+ ];
};
greeter = withDoctype ( { lang = "en"; } [