11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://demo-base-blog.11ty.dev/
MIT License
1.23k stars 619 forks source link

Draft tags show up in tag pagination even when excluding drafts #156

Closed adamwolf closed 3 weeks ago

adamwolf commented 1 year ago

When I add a tag to fifthpost.md with tags: hello, tags.njk generates a page for the hello tag at _site/tags/hello/index.html.

It doesn't show up in the loop in tags-list.njk, which is nice.

Is there a good way to not include draft tags in that pagination?

(I tried to dig into this a bit but I have to admit that although it works fine for me whenever I'm doing anything normal, I don't have my head around nitty gritty of how page data is processed.)

adamwolf commented 10 months ago

I ended up working around this with something like the following:

---js
{
    pagination: {
        data: "collections",
        size: 1,
        addAllPagesToCollections: true,
        alias: "tag",
        filter: [
            "all",
        ],
        before: function(paginationData, fullData) {
            // Filter out collections that don't have any items. (This fixes an issue where draft entry tags are included in production builds.)
            return paginationData.filter(entry => fullData.collections[entry].length > 0);
        },
    },
    permalink: "tags/{{ tag | slugify}}/",
    eleventyComputed: {
        title: data => `Tagged “${data.tag}”`,
    },
    layout: "layouts/blank.njk",
}
---
zachleat commented 3 weeks ago

You could also use:

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!