I am setting up a Hugo site with both markdown content files, located under the content directory, and static html files, currently located under the static/html directory. I am trying to create a public/sitemap.xml file with both the markdown content files, and the static html files. There are more then 1000 static html pages, so I figured it was a good idea to create a custom sitemap.xml in the layouts directory and read information about the static files from a data file in the data directory. With the configuration from the files below, the created public/sitemap.xml contains only entries related to the markdown content files. It seems that I am doing something wrong getting the data from the datafile with the static html info.
layouts/sitemap.xml
{{ 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 .Permalink -}}
<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 }}
{{- $static_html_files := .Site.Data.static_html_files }}
{{- range $static_html_files }}
<url>
<loc>{{ .url | safeHTML }}</loc>
<lastmod>{{ .lastmod | safeHTML }}</lastmod>
<changefreq>{{ .changefreq }}</changefreq>
<priority>0.5</priority>
</url>
{{- end }}
</urlset>
data/static-html-files.yml (passed validation)
static_html_files:
- url: https://www.mydomain.com/html/ls.html
lastmod: "2023-04-14T12:34:56Z"
changefreq: monthly
priority: 0.5
If I replace the entries below in the layouts/sitemap.xml file
{{- $static_html_files := .Site.Data.static_html_files }}
{{- range $static_html_files }}
<url>
<loc>{{ .url | safeHTML }}</loc>
<lastmod>{{ .lastmod | safeHTML }}</lastmod>
<changefreq>{{ .changefreq }}</changefreq>
<priority>0.5</priority>
</url>
{{- end }}
with
{{- $static_html_url := "https://www.mydomain.com/html/ls.html" }}
<url>
<loc>{{ $static_html_url | safeHTML }}</loc>
<lastmod>{{ .Date.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
then the entry “https://www.mydomain.com/html/ls.html” exists in the created public/sitemap.xml file. It seems there is something wrong reading from the data file data/static-html-files.yml There are no error messages when generating public/sitemap.xml
config.toml
baseURL = "https://www.mydomain.com"
languageCode = "en-us"
summaryLength = "10"
theme = "mytheme"
title = "mydomain"
enableRobotsTXT = true
[markup.goldmark.renderer]
unsafe= true
[markup.goldmark]
enableShortcodes = true
[privacy]
[privacy.disqus]
disable = true
[privacy.googleAnalytics]
anonymizeIP = true
disable = true
respectDoNotTrack = false
useSessionStorage = false
[privacy.instagram]
disable = true
simple = false
[privacy.twitter]
disable = true
enableDNT = false
simple = false
[privacy.vimeo]
disable = true
simple = false
[privacy.youtube]
disable = true
privacyEnhanced = true
# css plugins
[[params.plugins.css]]
URL = "plugins/bootstrap/bootstrap.min.css"
[[params.plugins.css]]
URL = "plugins/slick/slick.css"
[[params.plugins.css]]
URL = "plugins/themify-icons/themify-icons.css"
# js plugin
[[params.plugins.js]]
URL = "plugins/jQuery/jquery.min.js"
[[params.plugins.js]]
URL = "plugins/bootstrap/bootstrap.min.js"
[[params.plugins.js]]
URL = "plugins/slick/slick.min.js"
[[params.plugins.js]]
URL = "plugins/shuffle/shuffle.min.js"
# menu
[[menu.main]]
URL = "page1"
name = "Page1"
weight = 2
[[menu.main]]
URL = "page2"
name = "Page2"
weight = 3
[[menu.main]
URL = "page3"
name = "Page3"
weight = 4
[[menu.main]]
URL = "blog"
name = "Blog"
weight = 5
[[menu.main]]
URL = "contact"
name = "Contact"
weight = 6
# default parameters
[params]
title_tag = "mydomain"
home = "Home"
logo = "images/logo.png"
# theme color
theme_color = "#00438b"
# contact info
phone = "XXXXXXX"
email = "info@mydomain.com"
address = "YYY"
# meta description
author = "ZZZ"
description = "WWW"
# google analitycs
google_analitycs_id = "" # Your ID
# copyright
copyright = "Copyrighht © <script>document.write(new Date().getFullYear())</script> MyComp"
# contact
[params.contact]
enable = true
form_action = "https://formspree.io/maydoveg" # contact form works with : https://formspree.io
# preloader
[params.preloader]
enable = false
preloader = "" # use png, jpg, svg or gif format
# social site
[[params.social]]
URL = "#"
icon = "ti-facebook"
[[params.social]]
URL = "#"
icon = "ti-instagram"
[[params.social]]
URL = "#"
icon = "ti-dribbble"
[[params.social]]
URL = "#"
icon = "ti-twitter-alt"
[outputs]
home = ["HTML", "RSS", "JSON", "sitemap"]
I am using hugo v0.111.3-5d4eb5154e1fed125ca8e9b5a0315c4180dab192 linux/amd64
What am I doing wrong?