X Enterprises
Composables

useXBlog

Nuxt Content blog helpers — query the `blog` collection and normalize entries for the XMarkBlog* components.

useXBlog

Nuxt Content helpers for the layer's blog pages. Wraps queryCollection('blog') with normalization into the shape consumed by XMarkBlogCard / XMarkBlogList / XMarkBlogDetail. The layer's default /blog and /blog/[...slug] pages are built on this composable.

Posts are markdown files under content/blog/not fetched from an API.

Usage

const { getPosts, getPostByPath, getSurround } = useXBlog()

const posts = await getPosts({ limit: 6, tag: 'nuxt' })
const post = await getPostByPath('/blog/my-post')
const { previous, next } = await getSurround('/blog/my-post')

Returns

KeyTypeDescription
blogConfigComputedRef<object>The xMarketing.blog app config (active, title, description, meta).
normalizeBlogPost(doc: object) => XMarkBlogPostNormalizes a raw Content entry into the XMarkBlog* component shape (slug from path/stem, string→object author, minutes→"N min read" reading time, image/img reconciliation, published default true). Also exported standalone from the module.
getPosts(options?: { limit?: number, tag?: string, category?: string }) => Promise<XMarkBlogPost[]>Published posts, newest first (order('date', 'DESC')). tag / category filter in-memory; limit slices.
getPostByPath(path: string) => Promise<XMarkBlogPost | null>Single post by Content path (e.g. /blog/my-post). Returns null when not found.
getSurround(path: string) => Promise<{ previous: XMarkBlogPost | null, next: XMarkBlogPost | null }>Previous / next posts via queryCollectionItemSurroundings.

Requirements

  • @nuxt/content and better-sqlite3 peers installed (both required peers of the layer).
  • A consumer content.config.ts that declares the blog collection bound to your content dir — Nuxt Content v3 resolves a collection's source against the layer whose content.config.ts defines it, so the layer's shipped collection never sees your content/blog/*.md. See the gotcha + snippet on the index page.
  • Markdown posts under content/blog/*.md matching the blog schema (title, description, date, author, image, category, tags, published, readingTime).

No environment variables are required.

Breaking (2026-07):useXBlog no longer reads runtimeConfig.public.apiURL and no longer exposes get(). The old Builder.io / API-backed implementation was replaced by Nuxt Content queries — migrate posts to content/blog/*.md and drop NUXT_PUBLIC_API_URL / NUXT_PUBLIC_BUILDERIO_KEY.

AI Context

composable: useXBlog
package: "@xenterprises/nuxt-x-marketing"
use-when: >
  Reading blog posts from the Nuxt Content `blog` collection in pages or
  components that extend the nuxt-x-marketing layer. Returns blogConfig,
  normalizeBlogPost, getPosts({ limit, tag, category }), getPostByPath(path),
  and getSurround(path). Requires a consumer content.config.ts that re-declares
  the blog collection against the consumer's content dir, plus markdown under
  content/blog/. No env vars; the former apiURL/Builder.io get() API was
  removed in 2026-07.
Copyright © 2026