output formatted HTML
1 file changed, 23 insertions(+), 3 deletions(-)
changed files
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 + }) +}