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

Scoping tags to a tag #553

Closed tempertemper closed 5 years ago

tempertemper commented 5 years ago

I'm using tags for a few things on my website. For two of those things ('blog posts' and 'resources') I have category pages using Eleventy's zero maintenance method and my issue has been that I need them to be separate.

It's clunky and a fiddle to maintain, but I've been using filters. My resources category page filters out all of the blog post categories, and my blog post category page filters out all of the resource categories. This is fine if neither share the same tag/category name… But I've been limiting what I'm tagging things with in order to avoid a clash, which doesn't feel right.

Is there a way to scope the output of tag pages? i.e. can I dynamically define a group of tags to output, scoped to a particular tag?

An example of something I hoped might work was using data: collections.post for blog categories and removing all of the filters for resource tags/categories, instead of data: collections and all the filters. My hope was to output all of the tags on collections tagged with 'post'.

I'm guessing I'll need to do something in my .eleventy.js file (or maybe it's not possible) but I'm not sure where I'd start. Any help would be hugely appreciated 🙂

Ryuno-Ki commented 5 years ago

Would a collection filtered by tag work for you?

You could then filter inside their then.

danfascia commented 5 years ago

I would recommend firstly forming collections for your core types "post" and "resource" as suggested above.

Then you simply have the task of filtering within those for the tags you want and there are many ways of doing this.

Try this filter function which should be life changing for the purposes of filtering a collection. It even works on non-tag key:value pairs if you want to introduce another taxonomy.

https://gist.github.com/danfascia/e15b8e900a767c1b9677d1cbc74cc51c

zachleat commented 5 years ago

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 I will reopen the issue. Thanks!

tempertemper commented 5 years ago

@danfascia @Ryuno-Ki Thanks for the pointers – I've had the busiest few weeks so I'm really sorry I didn't get back to you to both on this. When I find myself with some more time I'll give the filtering within a tag technique a whirl. Thanks you!