Sitemap - What to Include?

Currently my sitemap looks like this. This is one entry, other look similar:

  <url>
    <loc>http://localhost:1313/de/posts/</loc>
    <lastmod>2024-06-16T14:10:00+02:00</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.5</priority>
    <xhtml:link href="http://localhost:1313/de/posts/" hreflang="x-default" rel="alternate"/>
    <xhtml:link href="http://localhost:1313/en/posts/" hreflang="en" rel="alternate"/>
    <xhtml:link href="http://localhost:1313/es/posts/" hreflang="es" rel="alternate"/>
    <xhtml:link href="http://localhost:1313/de/posts/" hreflang="de" rel="alternate"/>
  </url>
  ...

Question 1: Do I need to include into sitemap things like ‘posts’, ‘tags’, ‘categories’ or is it better to exclude them?

Question 2: Do I need to include ‘x-default’ hreflang attribute into sitemap?

Question 3: Do I need to include language versions links to sitemap at all?

Because in my Public folder there are folders for each language versions and inside every such folder there is separate sitemap.xml file. So maybe I just need one URL (without hreflang) in sitemaps?

Thank you.

Sitemap shall include your posts and all pages that you think are important for users to read.You can ignore tags, unless you doing smart tag usage to group articles together, simillar to categories.

I don’t see need to include x-default there as this is not a place for them.

When you enable Hugo multilingual, hugo is creating sitemap index file in root (sitemap.xml with template sitemapindex.xml) and in each language folder proper sitemap.xml (with sitemap.xml template)

My sitemap.xml template used on my multilingial site:

{{ 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 where .Pages "Sitemap.Disable" "ne" true }}
    {{- if .Permalink -}}
      <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="{{ .Language.LanguageCode }}"
                    href="{{ .Permalink }}"
                    />{{ end }}
        <xhtml:link
                    rel="alternate"
                    hreflang="{{ .Language.LanguageCode }}"
                    href="{{ .Permalink }}"
                    />{{ end }}
      </url>
    {{- end -}}
{{ end }}
</urlset>

Thanks, @idarek !
Good to know about x-default and what to include and what not.
So you do include language versions in sitemap.xml in each language folder.
Anyway, your reply is great food for thought.

Something extra for you to put into head.html

{{- $href := .Permalink -}}
  {{- with and .Page.IsNode .Paginator -}}
      {{- if gt .PageNumber 1 -}}
      {{- $href = .URL | absURL -}}
      {{- end -}}
  {{- end -}}
  <link rel="canonical" href="{{ $href }}">

  <link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
  {{ range .Translations }}<link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}">{{ end }}
  <link rel="alternate" href="{{ .Site.Params.langSelector | absURL }}" hreflang="x-default" />
2 Likes

deleted after reading the previous comment :wink: