diff options
Diffstat (limited to 'internal/sitemap')
-rw-r--r-- | internal/sitemap/sitemap.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/sitemap/sitemap.go b/internal/sitemap/sitemap.go new file mode 100644 index 0000000..b166f73 --- /dev/null +++ b/internal/sitemap/sitemap.go @@ -0,0 +1,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) +} |