Fri Jan 10 2020
Unasked Q: what's going on with the tags on your blog posts? why are some of them hyperlinks and some aren't?
Answered A: Converting the site over to 11ty has been a fun project.
Say you write blog posts in markdown, with frontmatter at the top. If you add a "posts" tag, that file is suddenly part of
collections.posts, which is available globally to be turned into individual posts, and/or paginated over to create lists of posts. If half of your markdown files also have a "music" tag, a separate
collections.music is available. You create templates to map-over and display the post-data in those arrays however you want.
The thing is, I don't really use tags this way in my general blog-blathering. I use tags more like a teenage Tumblr user... they're sometimes useful, but mostly tags are jokes ('"jokes"') or meta-commentary on the post itself. Or just non-sequitur nonsense. Whatever.
The problem is, all that nonsense gets turned into arrays full of objects, piling up on the global data object in 11ty. It's doesn't really hurt anything, as far as I can tell, but when I follow 11ty's Quick Tip #004 regarding no-maintenance tag pages, I end up building hundreds of pages, each for one (nonsensical, unlikely to ever be clicked) tag.
I really only want "useful" tag pages to be generated, so I built a sort-of filter thingie in the main 11ty config file. If a tag isn't used at least three times, it doesn't get into my bespoke
collections.tagList, and it's that
tagList array that gets processed into a list of tags on my /tags route. Similarly, when the blog post template renders each post, it loops over each tag in the post's data, and only if the tag is also in
collections.tagList does the tag get wrapped in a link. Otherwise it's list displayed as regular text.
I think there's probably a way to whitelist only the "useful" tags and/or blacklist all the goofy stuff, so that they don't get turned into hundreds of 1-item entries on the global
collections object, but this is a decent first step, I think.
Example: as I look at this post in draft, the
metatag is hyperlinked because I've used that tag several times. The
11tytag is not hyperlinked because this is only the second post using that tag. When I write a third one (soon I think; I'm going to write up a little music-playlist-y thing) and rebuild, the
11tytag will be hyperlinked, and a tag page built for it... ↩︎