11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.84k stars 487 forks source link

Paginated collections do not inherit data from root page #961

Open chriskrycho opened 4 years ago

chriskrycho commented 4 years ago

Describe the bug

I'm generating tag pages as suggested by Paging a Collection. In general, this works quite well! 🎉 However, the pages generated this way do not inherit the data from the root template used to generate the paginated view.

The problem here is that the resulting pages don't have any way of filtering on them other than perhaps by URL or digging down into the data on the object: they don't appear in any collections generated from the root template in particular. As such, they have to be special-cased in some way.

To Reproduce Steps to reproduce the behavior:

  1. Generate a paginated collection.
  2. Include the root file for that paginated collection in a (separate) collection itself in some way. (tags, custom collections, etc.). E.g. put it in a pages collection.
    • for extra clarity, set addAllPagesToCollections: true
  3. Render items that should filter to include or exclude items matching the collection (e.g. pages).
  4. Observe that none of the rendered items (e.g. individual tag pages) are appropriately filtered. 😱 If you dig into the data, you will note that they have the original item's metadata (e.g. the page tag), but this does not translate into their being included in the collection generated but that metadata.

Expected behavior

Each item rendered by the template is included in whatever collection(s) the template itself is included in and can be filtered accordingly.

Environment:

chriskrycho commented 4 years ago

I worked around this issue on my own website in this commit.

edwardhorsford commented 4 years ago

@chriskrycho I don't know if it helps, but I have filters for grabbing paginated or non-paginated pages. I think this would help you avoid needing to set standalonePage: true in your frontmatter.

// Items that are paginated by Eleventy
exports.paginatedOnly = (items) => {
    return items.filter( item => {
        return (typeof item.data.pagination !== 'undefined')
    })
}

// Items that are not paginated
exports.nonPaginatedOnly = (items) => {
    return items.filter( item => {
        return (typeof item.data.pagination == 'undefined')
    })
}