-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Means to exclude content from sitemap.xml #653
Comments
Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't. If this is a bug and you can still reproduce this error on the latest If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. |
This is a valid request. For example, it makes no sense to have the error pages like 404.html in sitemap.xml. Please, reconsider this. As a temp solution would be to provide your own sitemap.xml template and specify <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{ range .Data.Pages }}
{{ if not .Draft -}}
{{ if ne .Params.sitemap_exclude true -}}
<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 }}
{{- end }}
</urlset>
EDIT for newer Hugo versions: {{ 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 and .Permalink (ne .Params.sitemap_exclude true) }}
<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.Lang }}" href="{{ .Permalink }}"/>{{ end }}
<xhtml:link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}"/>{{ end }}
</url>{{ end }}{{ end }}
</urlset> |
I assume you can either:
And being an "Old and stale" issue shows that no one have shown enough interest in it to do something about it. Prove me wrong. |
I'm already doing this, but it's a functionality which can be very handy if it exists and will reduce custom code all around. It's a minor feature request, which will make Hugo even cooler :) I'm still in the process of using Hugo for the first time, so I notice some things coming from another generator. |
Related, Hugo should exclude the 404 page from sitemap.xml by default. It gives no value to have it in. |
@XhmikosR, please open a separate issue for removing the 404 template by default. |
I confirm interest in this topic. Landing page do not need to be indexed by robots, if you exulude them in robots.txt but you include them in sitemap google bots complain. |
Any updates on this? Maybe just respecting any frontend |
@XhmikosR no updates on this, but there are several similar requests floating around, making me think that this needs a general design and not loads of ad-hoc flags. |
Also note that if you really want this now, it is possible to override Hugo's sitemap template(s): https://gohugo.io/templates/sitemap-template/#sitemap-templates |
@bep: I know, I'm already using a custom sitemap template :) I was doing some cleanup in my templates and thought I'd try |
Hi, No coding skills there but trying to launch a website in HUGO. I have the same problem: I want to include in sitemap.xml only the posts of the website, excluding pages like "Search" or "Contact". Unfortunately I didn't find or understand how to do it with the Hugo's sitemap template (https://gohugo.io/templates/sitemap-template/#sitemap-templates) Any idea? |
@willertrombix - I recommend the method @XhmikosR provided. I've been using it on a number of sites and it works great. Simply add a
Then for your Search and Contact pages front matter add |
^^ |
oops ok - I edited my post. |
Hi guys! First of all, many thanks for your quick support, you rule! I've tried your solution (putting
So I deleted the sitemap.xml I used to have in
And I rung hugo server but in Maybe I'm doing something wrong? PD: I also tried |
sitemap.xml needs to be in layout folder. |
It works!! I really appreciate your help guys! |
Sorry for bothering you again... Any solution to also exclude tags from sitemap.xml? I mean tags are automatically created in Any idea? |
Hi all, I finally excluded tags from sitemap by putting this in
Hope it helps if you guys have the same problem :) |
@willertrombix No. The above empty However I would like to point out that GitHub issues are not meant for support. If you want please open a support topic in the Hugo Discussion Forum |
I'm working on this. @XhmikosR can you confirm if the 404 page showing up in the sitemap is still an issue for you as of Hugo v0.49? My site has a custom 404 page and it's not in my sitemap. |
This PR adds a new key to .Sitemap called `Exclude`. `Exclude` is a boolean that is set to false by default meaning all available pages are included. This is the behavior currently. When `Exclude` is set to true, it will not appear in any `sitemap.xml` files that Hugo may generate. `Exclude` can be set to true in the Hugo config turning `sitemap.xml` into an opt-in rather than an opt-out. Fixes gohugoio#653
The issue(404 page included in sitemap.xml) still exists when generating site by hugo 0.53. You can reproduce it via the theme dream plus. |
This PR adds a new key to .Sitemap called `Exclude`. `Exclude` is a boolean that is set to false by default meaning all available pages are included. This is the behavior currently. When `Exclude` is set to true, it will not appear in any `sitemap.xml` files that Hugo may generate. `Exclude` can be set to true in the Hugo config turning `sitemap.xml` into an opt-in rather than an opt-out. Fixes gohugoio#653
This PR adds a new key to .Sitemap called `Exclude`. `Exclude` is a boolean that is set to false by default meaning all available pages are included. This is the behavior currently. When `Exclude` is set to true, it will not appear in any `sitemap.xml` files that Hugo may generate. `Exclude` can be set to true in the Hugo config turning `sitemap.xml` into an opt-in rather than an opt-out. Fixes gohugoio#653
This PR adds a new key to .Sitemap called `Exclude`. `Exclude` is a boolean that is set to false by default meaning all available pages are included. This is the behavior currently. When `Exclude` is set to true, it will not appear in any `sitemap.xml` files that Hugo may generate. `Exclude` can be set to true in the Hugo config turning `sitemap.xml` into an opt-in rather than an opt-out. Fixes gohugoio#653
This PR adds a new key to .Sitemap called `Exclude`. `Exclude` is a boolean that is set to false by default meaning all available pages are included. This is the behavior currently. When `Exclude` is set to true, it will not appear in any `sitemap.xml` files that Hugo may generate. `Exclude` can be set to true in the Hugo config turning `sitemap.xml` into an opt-in rather than an opt-out. Fixes gohugoio#653
This PR adds a new key to .Sitemap called `Exclude`. `Exclude` is a boolean that is set to false by default meaning all available pages are included. This is the behavior currently. When `Exclude` is set to true, it will not appear in any `sitemap.xml` files that Hugo may generate. `Exclude` can be set to true in the Hugo config turning `sitemap.xml` into an opt-in rather than an opt-out. Fixes gohugoio#653
I have used I'm also trying to see where the sitemap is built. |
It would be great to see @FelicianoTech's changes in PR #6370 reviewed! Seems like it would successfully implement one of the oldest feature requests in Hugo too. 😀 |
I was surprised this didn't already work with the I was able to workaround this issue by simply adding an if conditional for the existing Draft front matter variable to an overridden default Hugo sitemap.xml template inside
This 2 line fix is working great for me without any additional front matter variables required. |
See #6370 (comment). |
@jmooring I have created a PR that only makes the suggested one line change. Will this be considered? |
Yes. |
Define global inclusion/exclusion in site configuration, and override via front matter. For example, to exclude a page from the sitemap: [sitemap] disable = true # default is false Closes gohugoio#653 Closes gohugoio#12282 Co-authored-by: kolappannathan <kolappannathan@users.noreply.github.com> Co-authored-by: felicianotech <FelicianoTech@gmail.com>
Define global inclusion/exclusion in site configuration, and override via front matter. For example, to exclude a page from the sitemap: [sitemap] disable = true # default is false Closes #653 Closes #12282 Co-authored-by: kolappannathan <kolappannathan@users.noreply.github.com> Co-authored-by: felicianotech <FelicianoTech@gmail.com>
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I've looked through the existing documentation on the "Front Matter" and have not been able to find an option to exclude content from appearing in the sitemap.
This use case arises when we want content to be included in "master" pages. For example, our careers page lists all careers by ranging over
.Data.Pages
and displaying the title and content (which amounts to a brief description), though we technically do not want each individual career to have its own landing page.Normally this isn't an issue, but it becomes one on the sitemap.xml as the pages, which shouldn't really have their own URL, are included in the sitemap. As these pieces of content don't have dates associated with them, Google Webmaster Tools reports an invalid date. It also produces a fairly pointless URL with negligible content.
The text was updated successfully, but these errors were encountered: