Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the four predefined front matter date fields when type is string #10717

Closed
snicolai opened this issue Feb 12, 2023 · 7 comments · Fixed by #12877
Closed

Validate the four predefined front matter date fields when type is string #10717

snicolai opened this issue Feb 12, 2023 · 7 comments · Fixed by #12877
Milestone

Comments

@snicolai
Copy link

snicolai commented Feb 12, 2023

with hugo v0.110.0+extended darwin/arm64 BuildDate=unknown from brew

With the following front matter on a page in index.md

---
title: "foo"
date: 2023-02-010T17:46:51-06:00
draft: true
---

Note the extra zero in the day portion of the date.

The page will not be generated and no error message will be issued. I would expect an error message about an unparsable date.

@jmooring
Copy link
Member

jmooring commented Feb 12, 2023

I agree that it would be helpful if the 4 front matter date fields were validated for JSON and YAML. With these formats, any date that you provide is a string---there is not a native date type.

When using TOML, where dates are a native type, github.com/pelletier/go-toml throws an error when an unquoted value looks like a date but isn't a date.

The native date type provided by TOML is very useful when performing date comparisons involving custom date parameters in front matter.

@bep bep added this to the v0.112.0 milestone Feb 15, 2023
@MTLChrisLEE
Copy link

MTLChrisLEE commented Feb 18, 2023

Hi @snicolai @jmooring ,

I cannot reproduce on my end.

It does generate a page.

On my side, if the date format is wrong, no matter how it's wrong, the date is displayed as "Monday, Jan 1, 0001"

Screenshot from 2023-02-18 09-47-16

@snicolai-blog
Copy link

Perhaps it does generate the page, but sorts it into the wrong location, with 100s of posts and a pagination on the main page, it's likely not to be found.

@MTLChrisLEE
Copy link

As I showed in my previous comment, the page gets generated but the date becomes "Monday, Jan 1, 0001".
If the sorting is based on the date, it is highly probable that it's the first item or the last item.
If not, can you at least provide steps to reproduce it?

@mvarie
Copy link

mvarie commented Mar 18, 2023

It's also possible that the date is interpreted as being in the future, and in that case, no page is generated.

@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@jmooring jmooring changed the title Hugo silently ignores pages with badly formatted dates Validate the four predefined front matter date fields when type is string Nov 25, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Sep 24, 2024
bep pushed a commit to jmooring/hugo that referenced this issue Sep 27, 2024
@bep bep closed this as completed in 4c02a52 Sep 27, 2024
@jcallstrom
Copy link

The fix/change that went into 0.135.0 to "validate predefined font matter" dates appears to have broken when using a standard dates:

From .md file
date: September 29, 2024

Error: ERROR invalid front matter: date: September 29, 2024:

@jmooring
Copy link
Member

jmooring commented Sep 28, 2024

Hugo is doing what it should be doing... it's throwing an error because "September 29, 2024" cannot be cast into a time.Time value. Instead of throwing an error, prior versions silently interpreted your example to be the zero date (0001-01-01 00:00:00 +0000 UTC)... that's what we fixed.

Here are some examples of valid, parsable date strings:
https://gohugo.io/functions/time/astime/#parsable-strings

This issue is closed. Please use the forum (https://discourse.gohugo.io/) if you have additional questions. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants