· 2 min read · updated
Tag pages for the blog
Added /blog/tags/[tag]: one prerendered page per tag, with its posts grouped by year. /blog got a tag index with counts.
What we did
- Added
/blog/tags/[tag]: one prerendered page per tag, with its posts grouped by year./bloggot a tag index with counts. content.tsexportspostTags(every tag a post uses, once, A to Z) andpostsTagged(tag).checkTagsfails the build when a tag isn't lowercase kebab-case, and the error names the file.- Moved the tag list out of
TeaserCardandArticleHeaderintoTagList.svelte. It only links tags when it gets atagHreffunction. The blog passesblogTag(fromlinks.ts), and the Devlog passes nothing. handleUnseenRoutesignores/blog/tags/[tag]too, while every post is a draft.
What I learned
- Each entry's tags come from the
.map()intoList. The list of all tags is one more step over the finished list (flatMap, then aSet, thensort). The.map()sees one file at a time, so it can't build that list. postTagscomes fromallPosts, which has no drafts in a build. A tag only drafts use gets no page, with no extra code.- In a build with no published posts,
entries()returns nothing and nobody links to the route, so the crawler reports it as unseen. Once a published post has a tag, its card links to that tag's page, so the page can't go unseen. - Passing a function (
tagHref) keeps routes out ofTagList. A Devlog tag likeplanninghas no blog page: a hard-coded link would 404 and fail the build. - Rejecting a bad tag beats fixing it quietly. With
CSSandcss, a quiet fix would have to happen inpostTags,postsTagged, the link and the label. With one rule, every place can trust the data, and the build tells me which file to fix. - Small links in a list (not in a sentence) need to be at least 24px tall (WCAG 2.5.8).
padding-blockmakes them 26px.
Problems & fixes
- Lighthouse gave the tag page 98 for
heading-order: theh1went straight to the cards'h3. Grouping by year, like/blog, addsh2s and brought it back to 100. - With every post a draft, a build has no tag pages to test. I copied one draft into
content/blog/for the checks, then deleted it.
Links
Next
- Open the Phase 7 PR.