11ty / eleventy-plugin-webc

Adds support for WebC *.webc files to Eleventy
https://www.11ty.dev/docs/languages/webc/
120 stars 10 forks source link

Usage of getNextCollectionItem/getPreviousCollectionItem in webc #76

Closed janmonschke closed 1 year ago

janmonschke commented 1 year ago

Operating system

mac OS 13.1

Eleventy

2.0.1

Describe the bug

I'm trying to use getPreviousCollectionItem and getNextCollectionItem in a webc template but the build fails with the following error:

Cannot read properties of undefined (reading 'lang') (...)
at getLocaleCollectionItem (...)
GetLocaleCollectionItem.js:23:19

This is how I am trying to use it:

<script webc:setup>
    const prev = getPreviousCollectionItem(collections.blogPosts, page);
    const next = getNextCollectionItem(collections.blogPosts, page);
</script>

I checked the webc documentation but could not find an example on how to use these.

Reproduction steps

  1. Create a collection called blogPosts
  2. Try to render the above webc template (e.g. as a layout)

Expected behavior

The build should not fail and the webc template should get access to prev and next.

Reproduction URL

No response

Screenshots

No response

zachleat commented 1 year ago

Reproduced this one. Not sure if it belongs in @11ty/eleventy-plugin-webc yet!

zachleat commented 1 year ago

Depends on upstream node-retrieve-globals@2.0.8 (also ran into https://github.com/zachleat/node-retrieve-globals/issues/1 fixing this)

zachleat commented 1 year ago

This will ship with the next version of Eleventy WebC, thank you!

janmonschke commented 1 year ago

Wohooo, thanks for the quick fix!