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.xmllayouts\_default\home.authors.xmllayouts\_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.
<sitemap>
<loc>{{ .SitemapAbsURL }}</loc>
{{ if not .LastChange.IsZero }}
<lastmod>{{ .LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</lastmod>
{{ end }}
</sitemap>
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.
