Excluding taxonomies from sitemaps in multilingual sites

I do not want to include Categories and Tags URLs in the sitemap. Therefore, using the following custom sitemap template.

{{ 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 }}
  {{ if not (or (hasPrefix .RelPermalink "/tags") (hasPrefix .RelPermalink "/categories")) }}
  <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 }}
  {{ end }}
</urlset>

It works fine for the default (English) sitemap but not for the sitemap of other languages (French, Chinese). The Sitemaps for French and Chinese languages include Categories and Tags URLs.
https://blog-qa.conholdate.com/en/sitemap.xml
https://blog-qa.conholdate.com/fr/sitemap.xml

Thanks.

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.

See https://discourse.gohugo.io/t/requesting-help/9132.

Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Sorry! A link to the public repository is given below:

I did not check your repo, but it feels like your tags are not named tags in non English languages. A quick note I can leave would be that there is a .Data.RegularPages (“regular” content) as opposed to .Data.Pages (all pages) which might not contain tags/categories. Untested though.

See this line:
https://github.com/sohail-aspose/ConholdateHugoBlog/blob/main/layouts/_default/sitemap.xml#L5

The .RelPermalink values for the fr and zh pages will begin with /fr and /zh respectively, so they do not trigger the filter.

Replace that line with:

{{ $path := "" }}
{{ with .File }}
      {{ $path = .Path }}
{{ else }}
      {{ $path = .Path }}
{{ end }}
{{ if not (or (eq .Path "/tags") (eq .Path "/categories")) }}

Unfortunately, above both solutions didn’t work for me. I replaced the hasPrefix function with strings.Contains and it worked.

May I ask what are benefits of excluding tags from sitemap? In your instance?

I solved this with two templates, my samples behind this links

home.sitemap.xml and section.sitemap.xml in themes/photon/layouts/_default

The first generates include for all section sitemaps, can you create by hand or template

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xml:base="http://localhost/">
 <sitemap>
 <loc>/post/sitemap.xml</loc>
 </sitemap>
 <sitemap>
 <loc>/photo/sitemap.xml</loc>
 </sitemap>
</sitemapindex>

from config.toml

[outputs]
    home     = [ "HTML", "ATOM", "JSON", "FEED", "MANIFEST", "SITEMAP", "SEARCH"]
    section  = [ "HTML", "SITEMAP" ]

[outputFormats.SITEMAP]
    MediaType              = "application/xml"
    BaseName               = "sitemap"
    IsHTML                 = false
    IsPlainText            = true
    noUgly                 = true
    notAlternative         = true
    Rel                    = "sitemap"

HTH