From a2feb8c63c80a1f52830f562af2deb2c6065eaae Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 24 Jun 2024 21:48:36 +0200 Subject: move templ templates into separate package --- templates/page.templ | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 templates/page.templ (limited to 'templates/page.templ') diff --git a/templates/page.templ b/templates/page.templ new file mode 100644 index 0000000..08c17a0 --- /dev/null +++ b/templates/page.templ @@ -0,0 +1,115 @@ +package templates + +import ( + "os" + "net/url" + + "website/internal/config" +) + +var ( + css string +) + +func init() { + bytes, err := os.ReadFile("templates/style.css") + if err != nil { + panic(err) + } + css = string(bytes) +} + +type PageSettings struct { + Title string + Path string + TitleAttrs templ.Attributes + BodyAttrs templ.Attributes +} + +func extendClasses(cs string, attrs templ.Attributes) string { + if extras, exists := attrs["class"]; exists { + return templ.Classes(cs, extras).String() + } else { + return cs + } +} + +templ menuItem(item config.MenuItem) { + { item.Name } +} + +templ Page(site config.Config, page PageSettings) { + + + + + + { page.Title } + + @style(css) + + + +
+

+ { site.Title } +

+ +
+
+ { children... } +
+ + @counter(page.Path, page.Title) + if site.InjectLiveReload { + + } + + +} + +func mkURL(path string, title string) string { + u, err := url.Parse("https://alanpearce-eu.goatcounter.com/count") + if err != nil { + panic(err) + } + q := u.Query() + q.Add("p", path) + q.Add("t", title) + u.RawQuery = q.Encode() + + return u.String() +} + +templ counter(path string, title string) { + + +} + +func style(css string) templ.Component { + return templ.ComponentFunc(func(ctx context.Context, w io.Writer) (err error) { + _, err = io.WriteString(w, "") + return + }) +} -- cgit 1.4.1