Course contentsShow
← Web Development
Lesson 1786 of 2,98233. Static Site Generation and JamstackFree lesson

Taxonomy and Category Pages

Creating tag, category, and archive pages by aggregating and filtering data during the build process.

Taxonomy and Category Pages

You'll learn how to generate organized listing pages (like blog categories or product tags) automatically at build time by grouping and filtering your content data.

When you have a large collection of content—blog posts, products, recipes—you often want to organize it by categories, tags, or other taxonomies. In a static site, these archive pages are generated during the build process by reading all your content, grouping items by their metadata, and creating dedicated pages for each group.

How It Works

During the build, your static site generator reads all content files (from Markdown, a headless CMS, or GraphQL queries) and extracts taxonomy information like category: "JavaScript" or tags: ["React", "SSG"]. It then:

  1. Collects all unique categories/tags across your content
  2. Groups content items by each taxonomy value
  3. Generates a static page for each group (e.g., /category/javascript/, /tags/react/)
  4. Paginates if a category has many items

Think of it like sorting a deck of cards by suit—you're organizing pre-existing content into logical piles, then creating a "display page" for each pile.

Practical Pattern

// During build: generate pages for each category
export async function getStaticPaths() {
  const allPosts = await getAllPosts();
  
  // Extract unique categories
  const categories = [...new Set(allPosts.map(post => post.category))];
  
  // Create a path for each category
  return {
    paths: categories.map(cat => ({ params: { category: cat } })),
    fallback: false
  };
}

export async function getStaticProps({ params }) {
  const allPosts = await getAllPosts();
  
  // Filter posts for this category
  const postsInCategory = allPosts.filter(
    post => post.category === params.category
  );
  
  return { props: { posts: postsInCategory, category: params.category } };
}

Key Takeaway: Taxonomy pages are generated at build time by aggregating content metadata, grouping items by shared characteristics, and creating static archive pages for each category or tag—no runtime filtering needed.