about summary refs log tree commit diff stats
path: root/internal/sitemap/sitemap.go
blob: b166f7337635f374ce70e54ba8e04cfb5a782326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package sitemap

import (
	"io"
	"time"

	"go.alanpearce.eu/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)
}