about summary refs log tree commit diff stats
path: root/internal/builder/sitemap.go
diff options
context:
space:
mode:
authorAlan Pearce2024-06-05 22:15:05 +0200
committerAlan Pearce2024-06-05 22:15:05 +0200
commita9337d346ca6d82bbe203d50b176af9b7c146db0 (patch)
tree324818852995470cb4833bb6fe79dfead3d17957 /internal/builder/sitemap.go
parentab5a866278bec429657b61bf0d0a370757b5e922 (diff)
downloadwebsite-a9337d346ca6d82bbe203d50b176af9b7c146db0.tar.lz
website-a9337d346ca6d82bbe203d50b176af9b7c146db0.tar.zst
website-a9337d346ca6d82bbe203d50b176af9b7c146db0.zip
generate sitemap and robots.txt
Diffstat (limited to 'internal/builder/sitemap.go')
-rw-r--r--internal/builder/sitemap.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/builder/sitemap.go b/internal/builder/sitemap.go
new file mode 100644
index 0000000..81e3a31
--- /dev/null
+++ b/internal/builder/sitemap.go
@@ -0,0 +1,29 @@
+package builder
+
+import (
+	"io"
+	"website/internal/config"
+
+	"github.com/snabb/sitemap"
+)
+
+type Sitemap struct {
+	config  *config.Config
+	Sitemap *sitemap.Sitemap
+}
+
+func NewSitemap(cfg config.Config) *Sitemap {
+	return &Sitemap{
+		config:  &cfg,
+		Sitemap: sitemap.New(),
+	}
+}
+
+func (s *Sitemap) Add(u *sitemap.URL) {
+	u.Loc = s.config.BaseURL.JoinPath(u.Loc).String()
+	s.Sitemap.Add(u)
+}
+
+func (s *Sitemap) WriteTo(w io.Writer) (int64, error) {
+	return s.Sitemap.WriteTo(w)
+}