/
c-seo.go
60 lines (52 loc) · 1.37 KB
/
c-seo.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
package nut
import (
"fmt"
"net/http"
"github.com/ikeikeikeike/go-sitemap-generator/stm"
)
// GetGoogleVerify google verify file
// @router /google:code([\w]+).html [get]
func (p *Plugin) GetGoogleVerify() {
var code string
if err := Get("site.google.verify-code", &code); err != nil {
p.Abort(http.StatusInternalServerError, err)
}
if code != p.Ctx.Input.Param(":code") {
p.Abort(http.StatusNotFound, nil)
}
p.Ctx.WriteString(fmt.Sprintf("google-site-verification: google%s.html", code))
}
// GetBaiduVerify baidu verify file
// @router /baidu_verify_:code([\w]+).html”* [get]
func (p *Plugin) GetBaiduVerify() {
var code string
if err := Get("site.baidu.verify-code", &code); err != nil {
p.Abort(http.StatusInternalServerError, err)
}
if code != p.Ctx.Input.Param(":code") {
p.Abort(http.StatusNotFound, nil)
}
p.Ctx.WriteString(code)
}
// GetSitemap sitemap
// @router /sitemap.xml [get]
func (p *Plugin) GetSitemap() {
sm := stm.NewSitemap()
sm.SetDefaultHost(p.HomeURL())
sm.SetCompress(true)
sm.SetSitemapsPath("/")
sm.Create()
for _, l := range p.Data["languages"].([]string) {
sm.Add(stm.URL{"loc": "/?locale=" + l})
}
for _, h := range _sitemapHandlers {
urls, err := h()
if err != nil {
p.Abort(http.StatusInternalServerError, err)
}
for _, u := range urls {
sm.Add(stm.URL{"loc": u})
}
}
p.Ctx.ResponseWriter.Write(sm.XMLContent())
}