Visitar URL original
`eleventyConfig.addDateParsing` callbacks can return invalid `DateTime`s · Issue #4407 · 11ty/buildawesome · GitHub
Skip to content

eleventyConfig.addDateParsing callbacks can return invalid DateTimes #4407

Open

Description

@cypressSap

Operating system

Debian 12

Eleventy

3.1.7, 4.0.0-alpha.10

Describe the bug

  1. Use this example config from the docs
  2. Set date in some file's front matter to an invalid string:
---
date: goo goo ga ga
---

{{ page.date }}
  1. Run Eleventy. Without the date parsing function, it throws an error:
$ npx @11ty/eleventy
[11ty] Problem writing Eleventy templates:
[11ty] Data cascade value for `date` (goo goo ga ga) is invalid for ./foo.md

...but with the function, it "works":

$ npx @11ty/eleventy
[11ty] Writing ./_site/foo/index.html from ./foo.md (liquid)
[11ty] Wrote 1 file in 0.08 seconds (v3.1.7)
<p>Invalid Date</p>

Making the return in here conditional seems to fix it (or at least returns to throwing an error):

if (dateValue.isValid) return dateValue.toJSDate();
$ npx @11ty/eleventy
[11ty] Problem writing Eleventy templates:
[11ty] Data cascade value for `date` (Invalid DateTime) is invalid for ./foo.md. Expected a JavaScript Date instance, luxon DateTime instance, or String value.

Reproduction Source Code URL

No response

Screenshots

No response

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions