Skip to content

AI Agent Authoring

AI Agent Authoring

Yamblog is designed for AI agents as a first-class authoring workflow. A post is just a markdown file with a YAML frontmatter block — trivial to generate, validate, and update programmatically.

What an agent can do

  • Create a .md file in content/posts/ with valid frontmatter
  • Populate required and optional metadata fields
  • Write the body in markdown with correct heading hierarchy
  • Validate the post by calling blog.getPostBySlug(slug) — any parse error throws
  • Update an existing post by editing frontmatter or body
  • Set draft: false to publish, draft: true to unpublish

Authoring steps

  1. Choose a slug — derive a stable, URL-safe slug from the title. Rules: lowercase, hyphens, ASCII only. Example: "How I Built X"how-i-built-x.

  2. Write frontmatter — populate all required fields, plus optional ones as relevant:

    ---
    title: "How I Built X"
    date: "2026-05-08"
    author: "Agent Name"
    tags: ["tutorial", "typescript"]
    excerpt: "A one-sentence summary used in listings and OpenGraph."
    draft: false
    ---

    Do not include slug in frontmatter — it is derived from the filename automatically.

  3. Write the body — compose markdown. Start with ## headings (not #, which duplicates the title). Keep paragraphs focused.

  4. Validate — call the API to confirm parsing succeeds:

    import { defineBlog } from '@yamblog/core';
    const blog = defineBlog('content/posts');
    const post = await blog.getPostBySlug('how-i-built-x');
    console.log(post.id, post.readingTime);

    If the frontmatter is invalid (wrong type, missing required field) this throws — fix the file and retry.

  5. Publish — set draft: false (already set in step 2 if publishing immediately).

Agent setup prompt

For a repo integration prompt that detects the framework, confirms platform support, creates a sample post, and self-heals on bad first attempts, use Prompt for LLMs.

Copy-paste this into any AI coding agent to bootstrap Yamblog authoring inside an already-configured project:

Install and configure Yamblog:
1. Install packages
npm install @yamblog/core @yamblog/next # Next.js
npm install @yamblog/core @yamblog/astro # Astro
npm install @yamblog/core @yamblog/react # Vite React
2. Create the content directory
mkdir -p content/posts
Create content/posts/hello-world.md with frontmatter:
title, slug, date, author, tags, excerpt, draft: false
3. Create the blog instance (lib/blog.ts)
import { defineBlog } from "@yamblog/core";
export const blog = defineBlog("content/posts");
// siteUrl auto-detected from NEXT_PUBLIC_BASE_URL / SITE / VERCEL_URL
4. Wire routes (Next.js App Router example)
app/blog/page.tsx → blog.getPosts()
app/blog/[slug]/page.tsx → blog.getPostBySlug(slug)
app/feed.xml/route.ts → createRssHandler(blog, { title, description })
app/sitemap.ts → createSitemapExport(blog)
5. Verify
npm run dev → open /blog
npm run build → no type errors
6. Optional enhancements
- OG image: createOgImageHandler in app/blog/[slug]/opengraph-image/route.ts
- Breadcrumb JSON-LD: generateBreadcrumbJsonLd in post page
- Static params: createStaticParams in generateStaticParams
- Search index: blog.generateSearchIndex() → public/search-index.json
- Wire post.id into comments / analytics service

Frontmatter field reference

FieldRequiredTypeNotes
titleyesstringPost title, used in metadata and listings
dateyesISO 8601 stringPublication date
authornostringDefaults to 'Anonymous'
tagsnostring[]Defaults to []
excerptnostringUsed in listings and OpenGraph description
draftnobooleantrue hides the post; defaults to false
featurednobooleanReturned by getFeaturedPosts(); defaults to false
categorynostringUsed by getPostsByCategory()
coverImagenostringURL or path to cover image

Computed fields (do not add to frontmatter)

FieldValue
id"blog-{slug}" — stable foreign key
slugDerived from filename — do not add to frontmatter
readingTimeMinutes at 200 WPM
contentRaw markdown body

Validation errors

Common mistakes and how to fix them:

ErrorFix
date is not a valid dateUse ISO 8601 format: "2026-01-15"
tags is not an arrayUse YAML array: tags: ["a", "b"]
Post not foundCheck the slug matches the filename (minus .md)
Schema validation failedCheck all required fields are present and typed correctly