Sitemapindex.xml creation at root for a non-multilingual website

As I have mentioned in the title, my site is not multilingual. My site has several sitemaps like

  • articles.xml
  • authors.xml
  • tags.xml

I am using the following method to generate these sitemaps :

I have created the template files under

  • layouts\_default\home.articles.xml
  • layouts\_default\home.authors.xml
  • layouts\_default\home.tags.xml

then in my config.toml I generate the sitemaps using custom output format (link to config.toml)

What I wish to do

Google suggests creating a sitemapindex.xml (a file that points to a list of sitemaps) and submit it.
I wish to do the same. My problem - how do I create a custom sitemapindex.xml file with url for each sitemap & it’s date modified. Stated in other words, how do I populate the {{ .SitemapAbsURL }} & {{ .LastChange }} in the following code.

  <loc>{{ .SitemapAbsURL }}</loc>
   {{ if not .LastChange.IsZero }}
	 <lastmod>{{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
   {{ end }}

What I could do so far

I looked at the built-in sitemap template. I think there is no sitemapindex.xml being created for my site, since it is not multilingual.

I created layouts\_default\home.sitemapindex.xml (link here) looking at the template & also modified my config.toml accordingly . It resulted in the following error:

ERROR 2021/12/06 00:28:39 Failed to render pages: render of "home" failed: "D:\folderx\layouts\_default\home.sitemapindex.xml:3:12": execute of template failed: template: _default/home.sitemapindex.xml:3:12: executing "_default/home.sitemapindex.xml" at <.>: range can't iterate over {[0xc001092c60 0xc001092d80 0xc001092ea0 0xc001092fc0] 0xc001092fc0 0xc000cf4000}

Option 2

I thought instead of programmatically generating the sitemapindex.xml file, I can simply type it out & put it in static folder. But then I have to update <lastmod> for every deploy & for every sitemap… which becomes a trouble (too much of manual work).

Option 3

Use a regex based solution to identify files of type *.xml & then use the file location & date modified to create the sitemapindex. But I don’t know how to do this.

working sample here

change line 3 to

{{ range site.Sections }}

this resulted in:

which basically is but creating a sitemap.xml for each section. But this will not work for my site, since I have custom sitemap.xml files (not based on section). All my sitemaps are in root (not under section/ as generated by the above code).

Thanks for the help anyways.

PS: @ju52 I have searched & went through all the previous solutions that you have posted in this forum regarding sitemaps. I have read them all & even had looked at this repo which you just mentioned. By looking at the code of your home.sitemap.xml, I already knew that it will not be applicable to my site.

So, the built-in sitemap template is a little special – it gets a slice of Sites.

Any custom template using an output format definition will get a Page (e.g. the home page).

It should be possible to create a sitemapindex based on your setup, but you need to wrap your head around how your setup looks like…

Thanks for pitching in @bep . But I could not understand what exactly I need to do. I read the documentation regarding page variables accessible to sitemaps here, which says:
A sitemap is a Page and therefore has all the page variables. But I don’t think this is relevant for my case since I have custom sitemaps.