X Enterprises
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

KeyTypeDescription
configBlogConfigBlog 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 5.
getRelatedPosts(post, limit?)Promise<BlogPost[]>Fetch posts sharing tags with the given post, excluding the post itself. Defaults to 3.
formatDate(dateStr)stringFormat a date string as a localized short date (e.g. "Jan 15, 2025").
estimateReadingTime(text)numberEstimate reading time in minutes for the given text content (200 wpm, minimum 1).

getPosts(options?) Options

OptionTypeDefaultDescription
pagenumber1Page number to fetch.
tagstringFilter posts by this tag.
limitnumberpostsPerPageNumber 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?: unknown
}

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. estimateReadingTime()
  uses a fixed 200 wpm rate; formatDate() renders a localized short date.
  All queries target the 'blog' Nuxt Content collection — posts must
  live in content/blog/ with published: true in frontmatter.
Copyright © 2026