@shinyaz

Tag pages only looked at blog posts, causing 404 for TIL-only tags

1 min read

I noticed that visiting a tag page for a TIL-only tag (one not used by any blog post) returned a 404.

The cause was straightforward: getAllTags only looked at blog posts. Since generateStaticParams used this function, pages for TIL-exclusive tags were never generated in the first place.

// Before: only returns tags from blog posts
export function getAllTags(locale?: Locale) {
  const publishedPosts = getPublishedPosts(locale);
  const tagSet = new Set<string>();
  for (const post of publishedPosts) {
    for (const tag of post.tags) tagSet.add(tag);
  }
  return Array.from(tagSet).sort();
}

The fix was adding getAllTagsIncludingTils that imports tils and merges tags from both collections. The tag detail page now fetches both blog posts and TILs, showing them in separate sections when both exist.

When using Velite with multiple content collections (posts, tils), tag and category aggregation functions can silently ignore some collections. Whenever you add a new content type, double-check that shared features like tags still work across all of them.

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this site.The views and opinions expressed on this site are my own and do not represent the official positions of my employer.