Created
July 7, 2026 19:07
-
-
Save mike-moreau/d17ee709f0260b55638eaafb3fd703fc to your computer and use it in GitHub Desktop.
Exclude Children of Draft Parents in Hugo Sitemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {{/* gotmplfmt-ignore-all */ -}} | |
| {{ 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 }} | |
| {{- $hasAncestorDraft := false -}} | |
| {{- range .Ancestors -}} | |
| {{- if .Draft -}} | |
| {{- $hasAncestorDraft = true -}} | |
| {{- end -}} | |
| {{- end -}} | |
| {{- if and .Permalink (not $hasAncestorDraft) -}} | |
| <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 .AllTranslations }} | |
| <xhtml:link rel="alternate" hreflang="{{ .Language.Locale }}" href="{{ .Permalink }}"/>{{ end }}{{ end }} | |
| </url> | |
| {{ end -}} | |
| {{- end -}} | |
| </urlset> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drafts are excluded from Hugo's sitemap automatically, but if you want to exclude pages nested under a draft parent you need to add a custom sitemap.xml file.