output formatted HTML
4 files changed, 29 insertions(+), 3 deletions(-)
M go.mod → go.mod
@@ -7,6 +7,7 @@ require ( github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/PuerkitoBio/goquery v1.10.2 + github.com/a-h/htmlformat v0.0.0-20250209132643-c2a3d62ad1fc github.com/adrg/frontmatter v0.2.0 github.com/andybalholm/brotli v1.1.1 github.com/antchfx/xmlquery v1.4.4
M go.sum → go.sum
@@ -16,6 +16,8 @@ github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw= github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/PuerkitoBio/goquery v1.10.2 h1:7fh2BdHcG6VFZsK7toXBT/Bh1z5Wmy8Q9MV9HqT2AM8= github.com/PuerkitoBio/goquery v1.10.2/go.mod h1:0guWGjcLu9AYC7C1GHnpysHy056u9aEkUHwhdnePMCU= +github.com/a-h/htmlformat v0.0.0-20250209132643-c2a3d62ad1fc h1:ugx6msbScbUAaor0FD1PQFjnNituq3PUfl3lg0ISyKc= +github.com/a-h/htmlformat v0.0.0-20250209132643-c2a3d62ad1fc/go.mod h1:BAUXJJSwMZeh3MZH8teo/iI5QGUhmrmjHzh2lfssslQ= github.com/adrg/frontmatter v0.2.0 h1:/DgnNe82o03riBd1S+ZDjd43wAmC6W35q67NHeLkPd4= github.com/adrg/frontmatter v0.2.0/go.mod h1:93rQCj3z3ZlwyxxpQioRKC1wDLto4aXHrbqIsnH9wmE= github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
M gomod2nix.toml → gomod2nix.toml
@@ -22,6 +22,9 @@ hash = "sha256-XlFT3uxgpPYFTND54uO8fH33jtQqAHWa7zrv24nw/PE=" [mod."github.com/PuerkitoBio/goquery"] version = "v1.10.2" hash = "sha256-2h4Ol31ucXHieeZUJq+xi7F5m2FzzsOKRLjUehA5lbE=" + [mod."github.com/a-h/htmlformat"] + version = "v0.0.0-20250209132643-c2a3d62ad1fc" + hash = "sha256-GGYwNBvZzdM3ak8c+qZVw1uxMiPVqigzFeENjdrAMnk=" [mod."github.com/adrg/frontmatter"] version = "v0.2.0" hash = "sha256-WJsVcdCpkIkjqUz5fJOFStZYwQlrcFzQ6+mZatZiimo="
M templates/layout.go → templates/layout.go
@@ -1,6 +1,10 @@ package templates import ( + "io" + + "github.com/a-h/htmlformat" + "gitlab.com/tozd/go/errors" "go.alanpearce.eu/homestead/internal/config" g "go.alanpearce.eu/gomponents"@@ -38,11 +42,10 @@ }) } func Layout(site SiteSettings, page PageSettings, children ...g.Node) g.Node { - return Doctype( + return FormattedDocument(Doctype( HTML( Lang(site.Language), Head( - Meta(Charset("utf-8")), Meta(Name("viewport"), Content("width=device-width, initial-scale=1.0")), TitleEl(g.Text(page.Title)), Link(@@ -87,7 +90,7 @@ g.If(site.InjectLiveReload, LiveReload, ), ), - )) + ))) } var LiveReload = Script(Defer(), g.Raw(`@@ -104,3 +107,20 @@ g.If(item.URL.IsAbs(), Target("_blank")), g.Text(item.Name), ) } + +func FormattedDocument(doc g.Node) g.Node { + return g.NodeFunc(func(w io.Writer) error { + pr, pw := io.Pipe() + defer pr.Close() + + go func() { + pw.CloseWithError(doc.Render(pw)) + }() + + if err := htmlformat.Document(w, pr); err != nil { + return errors.WithStack(err) + } + + return nil + }) +}