vmesel
March 31, 2025, 1:42pm
1
I’m trying to generate sitemaps across different segments, but I’m not being successful with that.
Here is my hugo config:
baseURL = 'https://website.com/'
languageCode = 'pt-br'
title = 'Awesome Website'
googleAnalytics = 'G-MYGAID001'
defaultContentLanguage = 'pt'
enableRobotsTXT = true
[languages]
[languages.pt]
languageCode = 'pt-BR'
languageDirection = 'ltr'
languageName = 'Português'
weight = 1
[sitemap]
changeFreq = 'weekly'
disable = false
filename = 'sitemap.xml'
priority = 0.5
[outputFormats.SITEMAP]
MediaType = "application/xml"
BaseName = "sitemap"
IsHTML = false
IsPlainText = true
noUgly = true
notAlternative = true
Rel = "sitemap"
[outputs]
home = ['html']
page = ['html']
rss = ['rss']
section = ['html', 'rss', 'sitemap']
taxonomy = ['html']
term = ['html']
[segments]
[segments.home]
[[segments.home.includes]]
kind = '{home,term,taxonomy,section}'
[segments.posts]
[[segments.posts.includes]]
path = '{/posts/**}'
I build the website using the commands:
hugo build --gc --templateMetrics --templateMetricsHints --logLevel=debug --minify --renderSegments home > hugo.home.log
hugo build --gc --templateMetrics --templateMetricsHints --logLevel=debug --minify --renderSegments posts > hugo.posts.log
kind = '{home,term,taxonomy,section,sitemap}'
vmesel
March 31, 2025, 3:50pm
3
And what should I do in order to render the sitemap for every section? Since the sections have pages, sections and sitemap kinds?
Perhaps I misunderstood. A site map is a map of the site. But you want to place one within each section?
vmesel
March 31, 2025, 6:46pm
5
As the sitemap.xml hugo provides has all the pages, it doesnt serve the purpose for my 50k + pages website.
I need to split the sitemap into multiple sections sitemap.xml, in order to achieve it, I’ve created a file called section.sitemap.xml
:
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:base="{{site.BaseURL }}">
{{ $limit := default 50000 site.Params.sitemapMax }}
{{ range first $limit .CurrentSection.RegularPages }}
{{ if .Permalink -}}
<url>
<loc>{{ .Permalink }}</loc>
{{ with .Lastmod }}<lastmod>{{ . | time.Format "2006-01-02T00:00:00-03:00" }}</lastmod>{{ end }}
{{ with .Sitemap.ChangeFreq }}<changefreq>{{ . }}</changefreq>{{end}}
{{ with .Sitemap.Priority }}<priority>{{ . }}</priority>{{end}}
</url>
{{ end }}
{{ end }}
</urlset>
But it’s not being rendered
The output looks right to me.
git clone --single-branch -b hugo-forum-topic-54170 https://github.com/jmooring/hugo-testing hugo-forum-topic-54170
cd hugo-forum-topic-54170
rm -rf public/ && hugo --renderSegments home && tree public
Result:
public/
├── categories/
│ └── index.html
├── posts/
│ ├── index.html
│ ├── index.xml
│ └── sitemap.xml <-- looks ok to me
├── tags/
│ └── index.html
├── favicon.ico
└── index.html
Then run:
rm -rf public/ && hugo --renderSegments posts && tree public
Result:
public/
├── posts/
│ ├── post-1/
│ │ └── index.html
│ ├── post-2/
│ │ └── index.html
│ └── post-3/
│ └── index.html
└── favicon.ico