Generate Blog Metadata

generate-blog-metadata.mjs

Generate blog post metadata index for efficient querying.

_scripts/generate-blog-metadata.mjs

Usage

npm run blog

Note: This script runs automatically before npm run build.

What It Does

  • Scans all .tsx files in src/content/post/
  • Extracts metadata exports from each post
  • Sorts posts by date (newest first)
  • Generates _data/_blog.json with compiled metadata

Extracted Metadata

  • title - Post title
  • description - Post description/excerpt
  • date - Publication date (YYYY-MM-DD format)
  • categories - Array of category strings
  • featuredImage - Path to featured image
  • author - Author name
  • slug - Auto-generated from filename

Blog Post Structure

// src/content/post/my-first-post.tsx
export const metadata = {
title: 'My First Blog Post',
description: 'A brief description of the post for SEO and previews',
date: '2025-12-04',
categories: ['Technology', 'Web Development'],
featuredImage: '/images/blog/first-post.jpg',
author: 'John Doe',
}
export default function Post() {
return (
<article>
<h1>My First Blog Post</h1>
<p>Content goes here...</p>
</article>
)
}

Output

Generates _data/_blog.json:

[
{
"slug": "my-first-post",
"title": "My First Blog Post",
"description": "A brief description...",
"date": "2025-12-04",
"categories": ["Technology", "Web Development"],
"featuredImage": "/images/blog/first-post.jpg",
"author": "John Doe"
}
]

When to Run

  • After creating new blog posts
  • After updating post metadata (title, date, categories, etc.)
  • Automatically runs before production build

Why This Exists

Instead of dynamically importing every blog post to list them, this script pre-generates a metadata index. This enables:

  • Fast blog listing pages (no component imports needed)
  • Efficient pagination
  • Quick category filtering
  • Better build performance

See also:

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2025 Web Plant Media, LLC