aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-03-21 10:30:20 -0700
committerChristine Dodrill <me@christine.website>2019-03-21 10:30:20 -0700
commitd9ed20cb2ce9109e47604e866d09e0b88a073ad6 (patch)
treef512fa7f37c906d18f2333e1b18aa40291d9e59f /cmd
parent27f177c94a7d142e5aec1e771e407448c152a1b7 (diff)
downloadxesite-d9ed20cb2ce9109e47604e866d09e0b88a073ad6.tar.xz
xesite-d9ed20cb2ce9109e47604e866d09e0b88a073ad6.zip
robots and sitemap
Diffstat (limited to 'cmd')
-rw-r--r--cmd/site/main.go46
1 files changed, 44 insertions, 2 deletions
diff --git a/cmd/site/main.go b/cmd/site/main.go
index 60619c7..4ea6fe8 100644
--- a/cmd/site/main.go
+++ b/cmd/site/main.go
@@ -19,6 +19,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
blackfriday "github.com/russross/blackfriday"
+ "github.com/snabb/sitemap"
"within.website/ln"
)
@@ -81,7 +82,8 @@ type Site struct {
rssFeed *feeds.Feed
jsonFeed *jsonfeed.Feed
- mux *http.ServeMux
+ mux *http.ServeMux
+ sitemap []byte
templates map[string]*template.Template
tlock sync.RWMutex
@@ -93,6 +95,8 @@ func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.mux.ServeHTTP(w, r)
}
+var arbDate = time.Date(2019, time.March, 21, 18, 0, 0, 0, time.UTC)
+
// Build creates a new Site instance or fails.
func Build() (*Site, error) {
type postFM struct {
@@ -100,6 +104,31 @@ func Build() (*Site, error) {
Date string
}
+ smi := sitemap.New()
+ smi.Add(&sitemap.URL{
+ Loc: "https://christine.website/resume",
+ LastMod: &arbDate,
+ ChangeFreq: sitemap.Monthly,
+ })
+
+ smi.Add(&sitemap.URL{
+ Loc: "https://christine.website/contact",
+ LastMod: &arbDate,
+ ChangeFreq: sitemap.Monthly,
+ })
+
+ smi.Add(&sitemap.URL{
+ Loc: "https://christine.website/",
+ LastMod: &arbDate,
+ ChangeFreq: sitemap.Monthly,
+ })
+
+ smi.Add(&sitemap.URL{
+ Loc: "https://christine.website/blog",
+ LastMod: &arbDate,
+ ChangeFreq: sitemap.Weekly,
+ })
+
s := &Site{
rssFeed: &feeds.Feed{
Title: "Christine Dodrill's Blog",
@@ -135,7 +164,7 @@ func Build() (*Site, error) {
if info.IsDir() {
return nil
}
-
+
fin, err := os.Open(path)
if err != nil {
return err
@@ -164,6 +193,12 @@ func Build() (*Site, error) {
}
s.Posts = append(s.Posts, p)
+ itime, _ := time.Parse("2006-01-02", p.Date)
+ smi.Add(&sitemap.URL{
+ Loc: "https://christine.website/" + p.Link,
+ LastMod: &itime,
+ ChangeFreq: sitemap.Monthly,
+ })
return nil
})
@@ -224,6 +259,13 @@ func Build() (*Site, error) {
s.mux.HandleFunc("/sw.js", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./static/js/sw.js")
})
+ s.mux.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
+ http.ServeFile(w, r, "./static/robots.txt")
+ })
+ s.mux.Handle("/sitemap.xml", middlewareMetrics("sitemap", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/xml")
+ smi.WriteTo(w)
+ })))
return s, nil
}