Composables
useBlog
Blog data access composable backed by queryCollection('blog') — fetch posts, tags, related posts, and paginated listings from Nuxt Content v3.
useBlog
All blog data access in one composable. Backed by Nuxt Content v3's queryCollection('blog'). Returns the app.config.ts blog config alongside async methods for fetching posts, tags, related posts, and paginated results. Used internally by the pre-built /blog and /blog/[...slug] pages — also available for custom pages and components.
Usage
const {
config,
getPosts,
getPostByPath,
getAllTags,
getRecentPosts,
getRelatedPosts,
formatDate,
estimateReadingTime,
} = useBlog()
Returns
| Key | Type | Description |
|---|---|---|
config | BlogConfig | Blog settings from app.config.ts (xBlog namespace). |
getPosts(options?) | Promise<{ posts, total, page, totalPages, hasMore }> | Fetch a paginated list of published posts. Supports page, tag, and limit options. |
getPostByPath(path) | Promise<BlogPost | null> | Fetch a single post by its content path. |
getAllTags() | Promise<{ tag: string, count: number }[]> | Fetch all tags with their post counts, sorted by count descending. |
getRecentPosts(limit?) | Promise<BlogPost[]> | Fetch the most recent published posts. Defaults to postsPerPage from config. |
getRelatedPosts(post, limit?) | Promise<BlogPost[]> | Fetch posts sharing tags with the given post, excluding the post itself. |
formatDate(dateStr) | string | Format an ISO date string using the dateFormat from config (e.g. "MMM d, yyyy"). |
estimateReadingTime(text) | number | Estimate reading time in minutes for the given text content. |
getPosts(options?) Options
| Option | Type | Default | Description |
|---|---|---|---|
page | number | 1 | Page number to fetch. |
tag | string | — | Filter posts by this tag. |
limit | number | postsPerPage | Number of posts per page. |
BlogPost Type
interface BlogPost {
id: string
path: string
title: string
description?: string
date: string
author?: string
image?: string
tags?: string[]
published?: boolean
readingTime?: number
body?: any
}
AI Context
composable: useBlog
package: "@xenterprises/nuxt-x-blog"
use-when: >
Fetching blog post data in any Nuxt page or component that extends
nuxt-x-blog. Use getPosts() for paginated listings, getPostByPath()
for individual post pages, getAllTags() for tag filter UIs, and
getRelatedPosts() for sidebar related-post widgets. formatDate() and
estimateReadingTime() respect app.config.ts settings automatically.
All queries target the 'blog' Nuxt Content collection — posts must
live in content/blog/ with published: true in frontmatter.
