You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
735 B
34 lines
735 B
package generator |
|
|
|
import ( |
|
"fmt" |
|
"time" |
|
) |
|
|
|
// GenerateSitemap generates a sitemap.xml |
|
func GenerateSitemap(urls []SitemapURL, siteURL string) string { |
|
sitemap := `<?xml version="1.0" encoding="UTF-8"?> |
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> |
|
` |
|
|
|
for _, url := range urls { |
|
sitemap += fmt.Sprintf(` <url> |
|
<loc>%s%s</loc> |
|
<lastmod>%s</lastmod> |
|
<changefreq>%s</changefreq> |
|
<priority>%.1f</priority> |
|
</url> |
|
`, siteURL, url.Path, url.LastMod.Format(time.RFC3339), url.ChangeFreq, url.Priority) |
|
} |
|
|
|
sitemap += `</urlset>` |
|
return sitemap |
|
} |
|
|
|
// SitemapURL represents a URL in the sitemap |
|
type SitemapURL struct { |
|
Path string |
|
LastMod time.Time |
|
ChangeFreq string |
|
Priority float64 |
|
}
|
|
|