about summary refs log tree commit diff stats
path: root/internal/sitemap
diff options
context:
space:
mode:
authorAlan Pearce2024-06-18 20:13:26 +0200
committerAlan Pearce2024-06-18 20:13:26 +0200
commitb27c96688785372787eb5c3c71a32767fab71ac4 (patch)
tree2e39bc6cd94724953cf917c509fb141d39690cf1 /internal/sitemap
parent1d247493e05cdc659e46cd3d8a01d5da1e893867 (diff)
downloadwebsite-b27c96688785372787eb5c3c71a32767fab71ac4.tar.lz
website-b27c96688785372787eb5c3c71a32767fab71ac4.tar.zst
website-b27c96688785372787eb5c3c71a32767fab71ac4.zip
split content and sitemap code from builder
Diffstat (limited to 'internal/sitemap')
-rw-r--r--internal/sitemap/sitemap.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/sitemap/sitemap.go b/internal/sitemap/sitemap.go
new file mode 100644
index 0000000..a38e277
--- /dev/null
+++ b/internal/sitemap/sitemap.go
@@ -0,0 +1,35 @@
+package sitemap
+
+import (
+	"io"
+	"time"
+	"website/internal/config"
+
+	"github.com/snabb/sitemap"
+)
+
+type Sitemap struct {
+	config  *config.Config
+	Sitemap *sitemap.Sitemap
+}
+
+func New(cfg config.Config) *Sitemap {
+	return &Sitemap{
+		config:  &cfg,
+		Sitemap: sitemap.New(),
+	}
+}
+
+func (s *Sitemap) AddPath(path string, lastMod time.Time) {
+	url := &sitemap.URL{
+		Loc: s.config.BaseURL.JoinPath(path).String(),
+	}
+	if !lastMod.IsZero() {
+		url.LastMod = &lastMod
+	}
+	s.Sitemap.Add(url)
+}
+
+func (s *Sitemap) WriteTo(w io.Writer) (int64, error) {
+	return s.Sitemap.WriteTo(w)
+}