-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_sitemap.go
71 lines (61 loc) · 1.51 KB
/
build_sitemap.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"encoding/xml"
"log"
"os"
"time"
)
type SiteMapLink struct {
XMLName xml.Name `xml:"url"`
Loc string `xml:"loc"`
LastMod time.Time `xml:"lastmod"`
Changefreq string `xml:"changefreq"` //always hourly daily weekly monthly yearly never
Priority float64 `xml:"priority"`
}
// //////////////////////////////////////////////////////////////////////////////
// Site Map
func GenerateSiteMap() {
var siteLinks []SiteMapLink
siteLinks = append(siteLinks, SiteMapLink{
Loc: "/",
LastMod: time.Now(),
Changefreq: "daily",
Priority: 1.0,
})
siteLinks = append(siteLinks, SiteMapLink{
Loc: "/blog/",
LastMod: time.Now(),
Changefreq: "daily",
Priority: 1.0,
})
for _, v := range genData.Feed {
siteLinks = append(siteLinks, SiteMapLink{
Loc: v.Link,
LastMod: v.Date,
Changefreq: "monthly",
Priority: 0.5,
})
}
for _, g := range genData.Gallery {
siteLinks = append(siteLinks, SiteMapLink{
Loc: g.Link,
LastMod: g.Date,
Changefreq: "monthly",
Priority: 0.5,
})
}
f, err := os.Create(publicHtmlRoot + "sitemap.xml")
CheckErrContext(err, "Error in Sitemap ")
f.WriteString(`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
`)
for _, v := range siteLinks {
s, err := xml.MarshalIndent(v, " ", " ")
if err != nil {
log.Fatalln("Problem writing link ", err)
}
f.Write(s)
}
f.WriteString(`</urlset><!--END-->`)
f.Close()
}