xuxin 316723d774 reorganize project structure | 2 tahun lalu | |
---|---|---|
.. | ||
README.md | 2 tahun lalu | |
http.go | 2 tahun lalu | |
ping.go | 2 tahun lalu | |
robots.go | 2 tahun lalu | |
robots_test.go | 2 tahun lalu | |
sitemap.go | 2 tahun lalu | |
sitemap_test.go | 2 tahun lalu | |
xml.go | 2 tahun lalu |
Create a sitemap
sitemap := SiteMap() // will use the default file name and path as '/sitemap.xml'
sitemap := SiteMap("product") // /product.xml
Register URLs
Register a raw string path
sitemap.RegisterRawString("/product1") // path mode
sitemap.RegisterRawString("https://qor5.dev.com/product1") //url mode
Register a regularURL
sitemap.RegisterURL(URL{Loc: "/product1"}, URL{Loc: "https://qor5.dev.com/product1"})
Register a contextFunc
sitemap.RegisterContextFunc(func(context.Context) []URL {
// fetch and generate the urls by the context
}
)
Register a model
type product struct{
...
}
// model need to implement this method
func (p product) Sitemap(ctx context.Context) []URL {
// fetch urls from db
}
sitemap.RegisterModel(&product{}) // path mode
Mount to HTTP ServeMux, will automatically fetch the host according to the request and put it in context.
serveMux := http.NewServeMux()
site.MountTo(serveMux)
Generate xml string data directly according to the host in the context
sitemap.EncodeToXml(WithHost("https://qor5.dev.com"))
Ping the search engine when the new sitemap is generated
PingBing(sitemap,WithHost("https://qor5.dev.com"))
PingGoogle(sitemap,WithHost("https://qor5.dev.com"))
PingAll(sitemap,WithHost("https://qor5.dev.com"))
index := SiteMapIndex().RegisterSiteMap(SiteMap(), SiteMap("product"), SiteMap("post")) // Register multiple sitemaps
index.EncodeToXml(WithHost("https://qor5.dev.com")) // Generate xml string data directly
index.MountTo(serveMux) // MountTo Mux
Create a robots
robots := Robots()
Register a agent
robot.Agent(GoogleAgent).Allow("/product1", "/product2") // Allow
robot.Agent(GoogleAgent).Disallow("/product1", "/product2") // Disallow
robot.Agent(GoogleAgent).AddSitemapUrl(sitemao.ToUrl(WithHost("https://qor5.dev.com")))
// Add a sitemap
Mount to HTTP ServeMux,
serveMux := http.NewServeMux()
robot.MountTo(serveMux)
Generate plain txt
robot.ToTxt()