switch from templ to gomponent
1 file changed, 78 insertions(+), 0 deletions(-)
changed files
A templates/layout.go
@@ -0,0 +1,78 @@ +package templates + +import ( + "go.alanpearce.eu/homestead/internal/config" + + g "maragu.dev/gomponents" + . "maragu.dev/gomponents/html" +) + +type SiteSettings struct { + Title string + Language string + Menu []config.MenuItem + InjectLiveReload bool +} + +type PageSettings struct { + Title string + TitleAttrs g.Node + BodyAttrs g.Node +} + +func Layout(site SiteSettings, page PageSettings, children ...g.Node) g.Node { + return 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( + Rel("alternate"), + Type("application/atom+xml"), + Title(site.Title), + Href("/atom.xml"), + ), + StyleEl(g.Raw(CSS)), + ), + Body( + A(Class("skip"), Href("#main"), g.Text("Skip to main content")), + Header( + H2( + A(page.TitleAttrs, Class("title p-name"), Href("/"), g.Text(site.Title)), + ), + Nav( + g.Map(site.Menu, func(item config.MenuItem) g.Node { + return A( + Href(item.URL.String()), + g.If(item.URL.IsAbs(), Target("_blank")), + g.Text(item.Name), + ) + }), + ), + ), + Main(ID("main"), g.Group(children)), + Footer( + g.Text("Content is "), + A( + Rel("license"), + Href("http://creativecommons.org/licenses/by/4.0/"), + g.Text("CC BY 4.0"), + ), + g.Text(". "), + A(Href("https://git.alanpearce.eu/website/"), g.Text("Site source code")), + g.Text(" is "), + A(Href("https://opensource.org/licenses/MIT"), g.Text("MIT")), + ), + g.If(site.InjectLiveReload, + Script(Defer(), g.Raw(` + new EventSource("/_/reload").onmessage = event => { + console.log("got message", event) + window.location.reload() + }; + `)), + ), + ), + )) +}