How can a layout check if disableKinds includes "sitemap"?

In layouts/robots.txt I have:

{{- $defaultSitemap := site.Home.Sitemap.Filename | absURL -}}

and later

{{ with $defaultSitemap }}Sitemap: {{ . | absURL }}{{ end -}}

But (with hugo server -b http://localhost:1313/ I always get Sitemap: http://localhost:1313/sitemap.xml in the output, even if in config.toml I have

disableKinds = ["sitemap","RSS"]

before any maps (like [params]). Is there a way for the robots.txt partial to detect if the sitemap is in fact generated for this site?

I’ve tried looking at .OutputFormats.Get "sitemap" and .AlternativeOutputFormats, but I haven’t found anything that will let me omit specifying a sitemap when there isn’t one.

If one of what I described ‘should work’ I’ll do up a test case, but based on going blind reading the docs, I can’t find anything that looks like it would do what I want, so I wanted ask if it is even possible.

This works:

disableKinds = ["sitemap"]
  filename = ''

With above in config.toml and this in a template file:

{{ with site.Home.Sitemap.Filename }}
    sitemap present
{{ else }}
    no sitemap
{{ end }}

I get “no sitemap”.

1 Like

Thank you! As a workaround that will get the job done in a better way than introducing a new param. I’d prefer not having to do a work around, but it’s not something I think worth an ‘feature request’ and then bep (most likely, if anyone) working on it.

I didn’t think of that, so thanks again :tada:


Saves some typing…

1 Like

@jmooring That’ll be nice for some uses - guess the docs haven’t caught up to the addition of that.

Unfortunately with @kaushalmodi’s workaround and baseURL set (but no <base href=...>) this returns the value of baseURL which means using an if instead of with. Not a big deal, but is less helpful than intended :face_with_diagonal_mouth: .

Ah well… I’m just happy I don’t have to introduce a new param, and I am grateful for the thought.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.