sitemap/template.go
2025-06-16 13:50:33 +05:00

36 lines
938 B
Go

package sitemap
import "text/template"
const (
templateText = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{ range . }}
<url>
<loc>{{ .Loc }}</loc>
{{ if .ChangeFreq }}
<changefreq>{{ .ChangeFreq }}</changefreq>
{{ end }}
{{ if .Priority }}
<priority>{{ .Priority }}</priority>
{{ end }}
{{ if .LastMod }}
<lastmod>{{ .LastMod }}</lastmod>
{{ end }}
</url>
{{ end }}
</urlset>
`
)
var (
parsedTemplate *template.Template
parsingError error
)
func init() {
// Try to parse the sitemap template, but defer error checking until execution.
parsedTemplate, parsingError = template.New("sitemap").Parse(templateText)
}