Search code examples
eleventy

What's the expected behaviour when adding "tags" to the front matter in Eleventy posts.json?


As far as I understood, adding a tags="post" inside the configuration file of a specific Eleventy directory, say "posts", adds the tag "post" to all the posts and creates the collections.post automatically. This doesn't seem to work for me, am I missing something? The only way I can iterate over a collections.post is if I either add the tag post per post (on each post front matter) or if I add a collection in .eleventy.js like so

eleventyConfig.addCollection("post", (collection) => {
  return collection.getFilteredByGlob("_posts/*.md");
});

Thanks.


Solution

  • I think it depends on what you mean by "configuration file of a specific Eleventy directory". To specify data for a directory, see the guide here, https://www.11ty.dev/docs/data-template-dir/, and scroll to Directory Data File. In theory you could add a JSON file named posts.11tydata.json inside the posts folder and set it up like so:

    {
    "tags":"post"
    }
    

    I'm mostly sure this works - testing now. ;)