HUGO

Add custom sitemap

Hey,

im trying to add another sitemap so i have 2 different sitemaps
im following the examples at https://gohugo.io/templates/sitemap-template/

i have added sitemap2.xml in layouts/_default/ but hugo does not create the file sitemap2.xml

i have copied the sample config:

{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
  {{ range .Data.Pages }}
  <url>
    <loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
    <lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
    <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
    <priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
  </url>
  {{ end }}
</urlset>

But it doesnt work, what am i doing wrong? do i need to add some variable in the config file?

Ok, this is a template - not a config :wink:

You must tell hugo to generate a second sitemap like this

[outputFormats.SITEMAP2]
    MediaType              = "application/xml"
    BaseName               = "sitemap2"
    IsHTML                 = false
    IsPlainText            = true
    Rel                    = "sitemap"

[outputs]
    home                   = [ "HTML", "SITEMAP", "SITEMAP2"]
1 Like