I’m in the process of migrating to hugo. I have successfully configured/amended the sitemap.xml template to produce the sitemap.
What I now want to do is produce a second sitemap “/videositemap.xml”. (Its purpose is obvious).
My fist step would be to duplicate the default “sitemap.xml” file as videositemap.xml and then somehow when building the site have that processed producing the output to /videositemap.xml (from there I could make the changes to the template that I would need to make)
I have experimented with additional output formats in config.toml and in the frontmatter of /index.md but really not gotten anywhere useful - and I am finding the existing documentation a bit sparse.
Any advice on how I can do this would be gratefully received, including but not limited to links to further material / reading that’ll get me there in hugo world.
Hi Rick. Thank you for your reply. Yours was one of the posts I had read before asking my question. Unless I am reading it wrongly or misunderstand it (which is very possible I admit) your post tells me to edit the sitemap.xml - and I could do that - but that would not make a second output document - merely would change the current sitemap.xml output. I am happy with the sitemap.xml I can create - I just want to create a second different one at the same time with a different output file.
I don’t have time to experiment today but, I think it’s a matter of getting your second sitemap template put in the right place and named right. Not sure, but you might need to make a dummy videositemap.md and put an “outputs” in its frontmatter to trigger use of that template.
I suspect this is mentioned in the docs, but you need a outputFormats definition (you got that covered) + a template (below /layouts) and then you need to tell Hugo when to use it (outputs).
Thanks - I am missing a bit for sure.
Just to check them.
output formats definition in config.toml? ok
template below layouts? ok
where’s the bit where I tell hugo to use it? A link please?
Also which bit of config tell hugo the name of the template to use?
I have added an outputs config and some progress is being made. However work commitments have stopped me going through it properly so I will report back after I have had a solid hack at it. I think I’ll try doing this on a clean hugo setup first too. Thanks again.
I’m sure there’s something fundamental that I am not getting. Been hacking at this for another hour. Currently no output is generated from
config.toml as:
[mediaTypes] emphasized text [mediaTypes.“videositemap/xml”]
suffixes = [“xml”]
Thanks. I did have that wrong and changed it to “_default” - in itself that had no effect. I tried several naming conventions for the videositemap file so the layouts now look like:
Thanks ju52. I added a home entry and a home.vidositemap.xml. That produced output (yay!) but it seems only for that one page. Other pages produce nothing so far - and I’m looking to produce one (second) videositemap.xml output file for every page on the site. Not a videositemap.xml for each page - I’m not sure if this gets us in that direction but it is progress of some kind.
Reading the entire alternative output formats section there’s nothing in it to say that that lends itself to the task of producing one new output file from many pages as with a sitemap. Then again it doesn’t say it wont do that either. However I presume that the processing that generates RSS and Sitemaps is “special” somehow.
EDIT:
Righto - I have a solution of sorts. It does not come with the confidence of complete understanding but with the input of your good selves I have achieved what looks like a workable option. So Thanks.
Here’s the pieces:
I have a template file _default/home.videositemap.xml
In that file I can range over .Data.Pages to get the whole site.
Using te hugo options –debug --log you can see what partials hugo is searching. It helped me to work out my solution. sitemap and RSS are special children for Hugo, with ATOM I had to research.
@gerardv - thanks for your research and writeup. I used the technique described in your post above and added a bit to it because I wanted to cull out any page with a url in the frontmatter. So I copied ./themes/docsy/userguide/layouts/sitemap.xml to layouts/sitemap.xml and added below the Range loop:
{{ if (not (isset .Params "url")) }}
Worked great to produce a sitemap without those redirect-only pages that specify a url.