🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Themes••By Komal Nakrani

Directory Website in Astro: Listings, Categories and Search

Build a directory website with Astro: a listings collection, category and tag pages, pagination, Pagefind search, submissions and how far a static directory scales.

#Astro#Directory Website#Content Collections#Pagination

To build a directory website with Astro, keep each listing as an entry in a content collection, generate category and tag pages with getStaticPaths() and paginate(), add Pagefind for search, and accept new listings through a form or a CMS that triggers a rebuild. The result is a static directory where every listing and every category has its own indexable URL, which is exactly what a directory needs to rank.

Key Takeaways

  • A directory is a content model problem first: decide listing fields, categories and tags before you design pages.
  • One collection with a strict schema powers listing pages, category pages, tag pages and the homepage.
  • paginate() splits long category pages into numbered, crawlable URLs.
  • Pagefind adds full-text search to a static directory with no server.
  • Static builds handle thousands of listings; switch to a CMS or database loader when editors outgrow files.

What makes a directory website work

Directories succeed on two things: coverage and findability. Visitors arrive from a search like “best note-taking apps for researchers” or “vegan cafes in Lisbon”, land on a category page, and click through to a listing. Each of those pages needs a stable URL, a clear title and content that differs from its neighbours.

Page type Example URL Built from
Homepage / Featured and newest listings
Category page /category/writing-tools/ All listings in one category
Paginated category /category/writing-tools/2/ The next page of the same list
Tag page /tag/open-source/ Listings with a tag
Listing page /listing/fieldnote/ One entry
Submit page /submit/ A form

Astro builds every one of these from the same collection, so adding a listing updates all the pages it appears on.

Model the listings

Start with the schema. Strict fields keep a directory consistent as it grows, and the build fails loudly when a submission is missing something:

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const categories = ['writing-tools', 'research', 'design', 'developer-tools'] as const;

const listings = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/listings' }),
  schema: ({ image }) =>
    z.object({
      name: z.string(),
      tagline: z.string().max(120),
      url: z.url(),
      category: z.enum(categories),
      tags: z.array(z.string()).default([]),
      pricing: z.enum(['free', 'freemium', 'paid']),
      logo: image().optional(),
      featured: z.boolean().default(false),
      added: z.coerce.date(),
    }),
});

export const collections = { listings };

A listing file holds the structured data in frontmatter and a short, original review in the body. That body text is what stops listing pages from being thin copies of the vendor’s homepage:

---
# src/content/listings/fieldnote.md
name: Fieldnote
tagline: Offline-first notebook for field researchers
url: https://fieldnote.example
category: research
tags: [offline, mobile, open-source]
pricing: freemium
added: 2026-10-20
---

Fieldnote stores notes locally and syncs when you're back online...

Using image() for logos means Astro validates that the file exists and optimizes it at build time. The content layer loaders guide covers other loaders if your listings live in a spreadsheet or an API instead of files.

Generate category and tag pages

Category pages are the pages most likely to rank, so give them real content and pagination. paginate() turns one long list into numbered pages and hands each page its data:

---
// src/pages/category/[category]/[...page].astro
import type { GetStaticPaths } from 'astro';
import { getCollection } from 'astro:content';
import Base from '../../../layouts/Base.astro';

export const getStaticPaths = (async ({ paginate }) => {
  const listings = await getCollection('listings');
  const categories = [...new Set(listings.map((l) => l.data.category))];

  return categories.flatMap((category) => {
    const items = listings
      .filter((l) => l.data.category === category)
      .sort((a, b) => a.data.name.localeCompare(b.data.name));
    return paginate(items, { params: { category }, pageSize: 24 });
  });
}) satisfies GetStaticPaths;

const { page } = Astro.props;
const { category } = Astro.params;
---
<Base title={`${category} tools (page ${page.currentPage})`} description={`Every ${category} tool in the directory.`}>
  <h1>{category}</h1>
  <ul>
    {page.data.map((l) => (
      <li><a href={`/listing/${l.id}/`}>{l.data.name}</a> {l.data.tagline}</li>
    ))}
  </ul>
  <nav aria-label="Pagination">
    {page.url.prev && <a href={page.url.prev}>Previous</a>}
    {page.url.next && <a href={page.url.next}>Next</a>}
  </nav>
</Base>

The rest parameter [...page] makes page 1 live at /category/writing-tools/ and later pages at /category/writing-tools/2/. Swap the raw slug in the heading for a human label from a lookup object, and add a short intro paragraph per category, ideally written by hand.

Tag pages follow the same pattern, with l.data.tags.includes(tag) as the filter. The pagination guide goes deeper, including canonical URLs for paginated lists.

Build the listing page

Each listing gets one static page. Keep outbound links honest: mark paid placements with rel="sponsored" and user-submitted links with rel="ugc" where that applies.

---
// src/pages/listing/[id].astro
import { getCollection, render } from 'astro:content';
import { Image } from 'astro:assets';
import Base from '../../layouts/Base.astro';

export async function getStaticPaths() {
  const listings = await getCollection('listings');
  return listings.map((listing) => ({ params: { id: listing.id }, props: { listing } }));
}

const { listing } = Astro.props;
const { Content } = await render(listing);
const related = (await getCollection('listings'))
  .filter((l) => l.data.category === listing.data.category && l.id !== listing.id)
  .slice(0, 4);
---
<Base title={`${listing.data.name}: ${listing.data.tagline}`} description={listing.data.tagline}>
  {listing.data.logo && <Image src={listing.data.logo} alt="" width={96} height={96} />}
  <h1>{listing.data.name}</h1>
  <p>{listing.data.tagline} · {listing.data.pricing}</p>
  <Content />
  <a href={listing.data.url} rel="noopener">Visit {listing.data.name}</a>

  <h2>Similar tools</h2>
  <ul>{related.map((r) => <li><a href={`/listing/${r.id}/`}>{r.data.name}</a></li>)}</ul>
</Base>

The “similar tools” block matters more than it looks. It links listings to each other, which helps crawlers reach deep pages and keeps visitors browsing.

Add search to the directory website

A static Astro directory can have fast full-text search through Pagefind. It runs after astro build, indexes the HTML in dist/, and ships a small search UI that loads its index on demand:

{
  "scripts": {
    "build": "astro build && npx pagefind --site dist"
  }
}

Add data-pagefind-body to the main content of listing pages so the index skips headers and footers, and data-pagefind-filter="category" on an element that holds the category to get filter facets. The Pagefind search guide walks through the UI component and filters.

For a directory with a handful of categories, simple client-side filtering on a single page also works: put the category and tags on each card as data- attributes and toggle hidden from a short script.

Structured data for directories

Search engines understand lists better with ItemList markup on category pages. Generate it from page.data so it always matches what’s on the page:

---
// inside src/pages/category/[category]/[...page].astro
const itemList = {
  '@context': 'https://schema.org',
  '@type': 'ItemList',
  itemListElement: page.data.map((l, i) => ({
    '@type': 'ListItem',
    position: page.start + i + 1,
    url: new URL(`/listing/${l.id}/`, Astro.site).href,
    name: l.data.name,
  })),
};
---
<script type="application/ld+json" set:html={JSON.stringify(itemList)} />

Listing pages can use a type that fits the subject, such as SoftwareApplication for tools or LocalBusiness for a local directory. Only mark up what’s visible on the page, and don’t add review ratings you didn’t collect.

Accept submissions

Most directories grow through submissions. Start simple and automate later:

  1. A submit form posting to a form backend, with fields that mirror your schema. You review and add the Markdown file.
  2. A Git-based CMS such as Keystatic or Decap CMS, so a moderator approves entries in a form that commits to the repo.
  3. A headless CMS or database with a content loader, once you have several editors or thousands of entries. A publish webhook triggers a rebuild.

Paid featured placements can stay simple too: a featured flag in the schema, set when payment clears, and a homepage section that lists featured entries.

How far a static directory scales

Astro builds thousands of static pages without trouble, and each listing also creates entries on category and tag pages. Build time grows with page count and image processing, so cache node_modules/.astro in CI to avoid re-optimizing logos on every build. When a directory needs instant updates, logged-in users or per-visitor content, render just those routes on demand with an adapter and keep the rest static. The Astro routing docs explain how static and on-demand routes sit side by side.

Start from a directory theme

Several Komal Nakrani themes are built for curated directories: Aggregator X for product discovery with category and tag pages, Curated X for resource lists with featured placements, and Cube for design inspiration with a submit page. Each ships as editable Astro source, so you can connect it to a collection like the one above.

FAQ

Can Astro handle a directory website with thousands of listings?

Yes. Astro generates thousands of static pages from a content collection, and each build only needs the data, not a running server. Cache build artifacts in CI to keep image processing fast, and move listings to a CMS or database loader when editing files becomes the bottleneck.

How do I add search to a static Astro directory?

Run Pagefind after astro build. It indexes the generated HTML and ships a search UI that loads small index chunks in the browser, so search works on any static host without a backend.

How do I let users submit listings to an Astro directory?

Add a submit page with a form that posts to a form backend or writes to a CMS. A moderator reviews each entry, and publishing it triggers a rebuild that creates the listing page and updates category pages.

How do I paginate category pages in Astro?

Use the paginate() function inside getStaticPaths() with a rest parameter route such as [...page].astro. Astro creates /category/name/, /category/name/2/ and so on, and passes page.data, page.url.prev and page.url.next to the template.

Is a directory website good for SEO?

It can be, when each listing and category page has original text, a unique title and useful internal links. Directories that copy vendor descriptions word for word tend to struggle, so write a short review for every listing.