all repos — homestead @ 0b574f8b6bd132f273403d76229be08cbd329d6b

Code for my website

output formatted HTML

Alan Pearce
commit

0b574f8b6bd132f273403d76229be08cbd329d6b

parent

53909e073d8a13c8a83e33ca087c6c28549025e9

1 file changed, 23 insertions(+), 3 deletions(-)

changed files
M templates/layout.gotemplates/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 + }) +}