about summary refs log tree commit diff stats
path: root/internal/builder/sitemap.go
diff options
context:
space:
mode:
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)
+}