Skip to content

docs(cookbook): add blog index recipe#8671

Open
youcefzemmar wants to merge 1 commit into
QwikDev:mainfrom
youcefzemmar:fix/add-a-blog-index-page-with-all-blog-posts-to-the-q
Open

docs(cookbook): add blog index recipe#8671
youcefzemmar wants to merge 1 commit into
QwikDev:mainfrom
youcefzemmar:fix/add-a-blog-index-page-with-all-blog-posts-to-the-q

Conversation

@youcefzemmar
Copy link
Copy Markdown

What

Adds a "Blog Index" cookbook recipe — how to build a listing page from MDX/MD files using import.meta.glob and Qwik City's frontmatter export. Includes a runnable demo at /demo/cookbook/blog-index/ with three sample posts (two .mdx, one .md).

Fixes #3796 — the issue asked for a blog index page in the Qwik City demo. maiieul's reply on the issue pointed at the docs ("That'll make it easy for us to add it to the docs!"), so this lands as a cookbook recipe rather than touching the starter apps.

Why

Listing posts from a folder is one of the most common questions for anyone shipping a content site on Qwik City. The glob-import recipe covers the general primitive, but it doesn't show the blog-specific pattern: read each module's frontmatter export, sort by date, link to each post's own route.

How it works

Each post is its own folder (posts/<slug>/index.mdx) so directory-based routing turns it into a real, navigable page. The index globs ./posts/*/index.{md,mdx} with eager: true — we only need metadata, so deferring the import would just add a microtask for no gain. The frontmatter export comes for free from Qwik City's MDX pipeline (packages/qwik-city/src/buildtime/markdown/rehype.ts re-exports parsed YAML as a named frontmatter export).

The demo intentionally uses a string YYYY-MM-DD date so lexicographic sort matches chronological sort. Reviewer-facing notes in the recipe call out how to extend with real Date objects, pagination, or tag filtering.

Files:

  • packages/docs/src/routes/docs/cookbook/blog-index/index.mdx — the recipe
  • packages/docs/src/routes/demo/cookbook/blog-index/ — the runnable demo (index.tsx + 3 posts)
  • packages/docs/src/routes/docs/cookbook/index.mdx — adds the recipe to the overview (alphabetized)
  • packages/docs/src/routes/docs/menu.md — adds the sidebar entry under Cookbook

Testing

  • Verified the recipe renders by reading the existing glob-import recipe and matching its CodeSandbox usage exactly — same src shape, same path-rewriting expectations (packages/docs/src/components/code-sandbox/index.tsx strips /src/routes/demo/demo).
  • Confirmed frontmatter is a named export on compiled MDX/MD modules in this repo by tracing parseFrontmatterexportFrontmatter in packages/qwik-city/src/buildtime/markdown/.
  • Could not run pnpm fmt / pnpm lint in this environment — pnpm store DB unavailable. Files were authored to match the project's Prettier config (2-space, single-quote, semi, trailing comma es5, print width 100) and the structure of glob-import/index.tsx.

Notes

  • No public API changes, so pnpm api.update was not needed.
  • @builder.io/qwik-docs is private; per AGENTS.md changesets cover published packages only, so no changeset.
  • Scoped to docs/cookbook + demo routes; no changes to starters, runtime, or build tooling.

Fixes #3796.

Adds a runnable demo at /demo/cookbook/blog-index/ that lists three sample posts
(.mdx and .md) discovered via import.meta.glob, with frontmatter typing and
sort-by-date. Adds the matching cookbook recipe and wires it into the cookbook
overview and the menu.

Fixes QwikDev#3796.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

⚠️ No Changeset found

Latest commit: a2123b8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@youcefzemmar youcefzemmar marked this pull request as ready for review May 27, 2026 18:09
@youcefzemmar youcefzemmar requested a review from a team as a code owner May 27, 2026 18:09

const postModules = import.meta.glob<PostModule>(
'./posts/*/index.{md,mdx}',
{ eager: true }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try it out on v2? eager: true is not needed there iirc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no need for eager:true then could you make a sister PR for V2? We won't be able to resolve it with merge conflicts 🤓

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check #8679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[📖] Add a blog index page with all blog posts to the qwik city demo

2 participants