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
| Key | Type | Description |
|---|---|---|
blogConfig | ComputedRef<object> | The xMarketing.blog app config (active, title, description, meta). |
normalizeBlogPost | (doc: object) => XMarkBlogPost | Normalizes 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/contentandbetter-sqlite3peers installed (both required peers of the layer).- A consumer
content.config.tsthat declares theblogcollection bound to your content dir — Nuxt Content v3 resolves a collection'ssourceagainst the layer whosecontent.config.tsdefines it, so the layer's shipped collection never sees yourcontent/blog/*.md. See the gotcha + snippet on the index page. - Markdown posts under
content/blog/*.mdmatching 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.
useStaggerReveal
Adds incremental transition-delay values to [data-reveal] children of a selector for staggered scroll animations.
useConsentTracking
Reads app.config.xMarketing.tracking and dynamically injects GTM / GA4 / Clarity / custom scripts only after the matching consent category is granted. Used by <XMarkPrivacyCookieConsent> and the consent-tracking.client.ts plugin.
