-
Notifications
You must be signed in to change notification settings - Fork 2
/
robots.go
47 lines (34 loc) · 876 Bytes
/
robots.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
// SPDX-License-Identifier: MIT
package builder
import (
"github.com/issue9/errwrap"
"github.com/caixw/blogit/internal/data"
"github.com/caixw/blogit/internal/vars"
)
func (b *Builder) buildRobots(d *data.Data) error {
if d.Robots == nil {
return nil
}
buf := &errwrap.Buffer{}
buf.Printf("# 当前文件由 %s 自动生成,请勿手动修改", vars.URL)
buf.WByte('\n').WByte('\n')
for _, agent := range d.Robots.Agents {
for _, a := range agent.Agent {
buf.Println("User-agent:", a)
}
for _, disallow := range agent.Disallow {
buf.Println("Disallow:", disallow)
}
for _, allow := range agent.Allow {
buf.Println("Allow:", allow)
}
buf.WByte('\n')
}
for _, sitemap := range d.Robots.Sitemaps {
buf.Println("Sitemap:", sitemap)
}
if buf.Err != nil {
return buf.Err
}
return b.appendFile(d.Robots.Path, buf.Bytes())
}