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

Bug with Filters in Computed Data #1061

Closed
nhoizey opened this issue Mar 30, 2020 · 3 comments
Closed

Bug with Filters in Computed Data #1061

nhoizey opened this issue Mar 30, 2020 · 3 comments
Labels

Comments

@nhoizey
Copy link
Contributor

nhoizey commented Mar 30, 2020

Describe the bug

I tried to replace all renderData in my templates with eleventyComputed, but the build now doesn't work.

To Reproduce

I used to have this YFM in this template:
https://github.com/nhoizey/nicolas-hoizey.com/blob/master/src/articles/index-months.njk

---
layout: page
pagination:
  data: collections.articlesByMonth
  size: 1
  alias: month
permalink: "articles/{{ month }}/"
renderData:
  title: Articles published in {{ month | monthString }}
---

I tried to replace renderData with eleventyComputed, but it gives me this error:

Problem writing Eleventy templates: (more in DEBUG output)
> Having trouble rendering njk template ./src/articles/index-months.njk

`TemplateContentRenderError` was thrown
> (./src/articles/index-months.njk)
  TypeError: Cannot read property 'replace' of undefined

`Template render error` was thrown:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] eleventy:build: `cross-env NODE_ENV=production eleventy`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] eleventy:build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nhoizey/.npm/_logs/2020-03-30T09_26_27_412Z-debug.log

I guess it comes from the alias because the error Cannot read property 'replace' of undefined comes from the monthString filter:
https://github.com/nhoizey/nicolas-hoizey.com/blob/master/src/_11ty/filters/dates.js#L7-L11

monthString: (month) => {
  // transforms "2020/02" into "February 2020"
  let fullDate = `${month.replace('/', '-')}-01T10:00:00.000Z`;
  return moment(fullDate).format('MMMM YYYY');
},

Expected behavior

I thought eleventyComputed was supposed to replace renderData completely.

Environment:

  • OS and Version: macOS 10.15.3
  • Eleventy Version 0.11.0-beta-3
@zachleat
Copy link
Member

What does the new failing one look like?

@nhoizey
Copy link
Contributor Author

nhoizey commented Mar 30, 2020

@zachleat do you mean the YFM that doesn't work?

Same as the other with just renderData replaced by eleventyComputed:

---
layout: page
pagination:
  data: collections.articlesByMonth
  size: 1
  alias: month
permalink: "articles/{{ month }}/"
eleventyComputed:
  title: Articles published in {{ month | monthString }}
---

@zachleat zachleat added bug and removed needs-triage labels Apr 1, 2020
@zachleat zachleat added this to the Eleventy v0.11.0 milestone Apr 1, 2020
@zachleat zachleat changed the title Is eleventyComputed supposed to replace renderData completely? Bug with filters in computed data Apr 1, 2020
@zachleat zachleat changed the title Bug with filters in computed data Bug with Filters in Computed Data Apr 1, 2020
@jasonday
Copy link

I read somewhere that the title should be in "" when using eleventyComputed, but I can't get eleventyComputed working either.

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

No branches or pull requests

3 participants