gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.94k stars 7.54k forks source link

resources/page: Validate predefined front matter dates #12877

Closed jmooring closed 1 month ago

jmooring commented 1 month ago

Closes #10717

jmooring commented 1 month ago

With this PR, front matter such as this...

publishDate = "2023-01-010"

...will throw an error such as:

invalid front matter: publishdate: 2023-01-010: see /home/jmooring/code/hugo-testing/content/posts/post-1.md

Note that unquoted TOML dates are already validated when unmarshaling front matter. This PR adds validation for the predefined front matter dates (TOML/YAML/JSON) when expressed as strings.

We already validate date fields in pages generated by content adapters by requiring time.Time values in the dates map, and the time.AsTime template function validates the value.