CMS Composables
API reference for content querying, contributor lookup, reading time, Schema.org, and layout composables provided by @nuxtify/cms.
Overview
- Provided by:
@nuxtify/cms - Source directory:
src/runtime/composables/
@nuxtify/cms auto-imports composables for draft-safe and schedule-aware Nuxt Content queries, contributor lookups, reading time, Schema.org structured data, and block alignment. It also supersedes useNuxtifyConfig() from @nuxtify/core and @nuxtify/pages so its return type includes the content and email.reply CMS options.
Public Content Queries
All three query composables wrap @nuxt/content query builders so that outside development mode (!import.meta.dev):
- Items with
draft: trueare automatically excluded (where('draft', '=', false)). - If the collection is listed in
content.scheduledCollections(oroptions.filterScheduledistrue), items whosepublishedAttimestamp is in the future are excluded (publishedAt IS NULL OR publishedAt <= nowIso).
In development (npm run dev), drafts and future-dated items remain visible for local preview.
Shared Options (UsePublicCollectionOptions)
| Option | Type | Default | Description |
|---|---|---|---|
filterScheduled | boolean | undefined | Explicitly enable (true) or disable (false) future publishedAt filtering for this query, overriding content.scheduledCollections. |
Preserving Nuxt async context in useAsyncData: When calling usePublicCollection, usePublicCollectionNavigation, or usePublicCollectionSurroundings inside an async useAsyncData handler — especially after a prior await — wrap each call in nuxtApp.runWithContext(...). The composables read useAppConfig() to check scheduledCollections; running inside nuxtApp.runWithContext(...) preserves Nuxt's async context across await boundaries in SSR and production builds.
const { data } = await useAsyncData('article-with-surround', async (nuxtApp) => {
const article = await nuxtApp.runWithContext(() =>
usePublicCollection('articles').path(route.path).first(),
)
if (!article) return null
const surround = await nuxtApp.runWithContext(() =>
usePublicCollectionSurroundings('articles', article.path, {
fields: ['description'],
}),
)
return { article, surround }
})
usePublicCollection(collection, options?)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/usePublicCollection.ts
Wraps queryCollection(collection) and returns the chainable Nuxt Content query builder (.path(), .where(), .order(), .limit(), .first(), .all(), etc.).
const { data: articles } = await useAsyncData('latest-articles', nuxtApp =>
nuxtApp.runWithContext(() =>
usePublicCollection('articles')
.order('publishedAt', 'DESC')
.limit(5)
.all(),
),
)
usePublicCollectionNavigation(collection, fields?, options?)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/usePublicCollectionNavigation.ts
Wraps queryCollectionNavigation(collection, fields) with production draft and scheduled-content filtering. Returns a chainable promise resolving to ContentNavigationItem[].
const { data: navigation } = await useAsyncData('docs-nav', nuxtApp =>
nuxtApp.runWithContext(() =>
usePublicCollectionNavigation('docs', ['icon']),
),
)
usePublicCollectionSurroundings(collection, path, opts?)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/usePublicCollectionSurroundings.ts
Wraps queryCollectionItemSurroundings(collection, path, opts) with production draft and scheduled-content filtering. Accepts standard Nuxt Content SurroundOptions (before, after, fields) merged with filterScheduled.
Content & UI Helpers
useContributor(slug)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/useContributor.ts
Fetches a contributor document from the contributors collection via useAsyncData, trying the configured contributors.routePrefix path first and falling back to a stem LIKE %/<slug> lookup.
const { data: author } = await useContributor(() => article.value?.author)
| Parameter | Type | Description |
|---|---|---|
slug | MaybeRefOrGetter<string | undefined> | Contributor filename slug (for example, 'jane-doe'). Skips immediate execution when empty. |
useReadingTime(article)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/useReadingTime.ts
Returns a ComputedRef<number | string | undefined> estimating reading time from article.body (using countDocumentWords and content.articles.readTime.wordsPerMinute). Returns undefined when readTime.enabled === false, honors an explicit frontmatter readTime override if set, returns '< 1' when under one minute, and rounds up with Math.ceil otherwise.
const readTime = useReadingTime(article)
useAlignment(align)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/useAlignment.ts
Maps a reactive 'left' | 'center' | 'right' | undefined ref to Vuetify flex justification and text alignment classes.
const { justify, textAlign } = useAlignment(toRef(props, 'align'))
// 'left' -> { justify: 'start', textAlign: 'text-left' }
// 'right' -> { justify: 'end', textAlign: 'text-right' }
// 'center' -> { justify: 'center', textAlign: 'text-center' }
useTocScrollspy(headingIds)
- Provided by:
@nuxtify/cms(internal composable imported directly byPageToc) - Source:
src/runtime/composables/toc/useTocScrollspy.ts
Tracks visible heading elements with IntersectionObserver, honors scroll-margin-top / --v-layout-top offsets, and locks active-heading updates briefly during smooth programmatic scrolling. Returns { activeId, startObserver, stopObserver, stopScrollLock, scrollToId }.
Schema.org Composables
These three composables build clean JSON-LD nodes (stripping Markdown from descriptions, normalizing image paths, omitting empty fields, and respecting frontmatter schemaOrg overrides) and register them via useSchemaOrg(). See SEO & Schema.org for full guidance.
useContentPageSchema(docRef, options?)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/useContentPageSchema.ts
Registers WebPage (or a custom @type such as 'CollectionPage' or 'AboutPage') plus an optional BreadcrumbList for standard pages, collection indexes, and topic hubs.
| Option | Type | Description |
|---|---|---|
type | MaybeRefOrGetter<string | undefined> | Override Schema.org WebPage @type (e.g., 'CollectionPage'). |
breadcrumbs | MaybeRefOrGetter<BreadcrumbItem[] | undefined> | Parent breadcrumb items; the current page is appended automatically. |
headline | MaybeRefOrGetter<string | undefined> | Explicit headline / page name fallback. |
breadcrumbTitle | MaybeRefOrGetter<string | undefined> | Concise label for the final breadcrumb item. |
description | MaybeRefOrGetter<string | undefined> | Explicit description fallback. |
image | MaybeRefOrGetter<string | undefined> | Explicit image path or URL fallback. |
path | MaybeRefOrGetter<string | undefined> | Explicit current route path for breadcrumb termination. |
useArticleSchema(options)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/useArticleSchema.ts
Registers Article / BlogPosting (or another ArticleSchemaType) plus Person author metadata, word count, section, keywords, and BreadcrumbList for articles and notes. Automatically reads siteUrl, contributorsPrefix, and contributorsEnabled from runtime config unless overridden.
| Option | Type | Description |
|---|---|---|
doc | MaybeRefOrGetter<Article | Note | null | undefined> | Article or note document. |
author | MaybeRefOrGetter<Contributor | null | undefined> | Resolved contributor record. |
authorSlug | MaybeRefOrGetter<string | undefined> | Contributor slug override (defaults to doc.author). |
schemaType | MaybeRefOrGetter<ArticleSchemaType | undefined> | Fallback @type when frontmatter schemaType is omitted. |
breadcrumbs | MaybeRefOrGetter<BreadcrumbItem[] | undefined> | Parent breadcrumb items. |
keywords | MaybeRefOrGetter<string[] | undefined> | Normalized topic or tag keywords. |
section | MaybeRefOrGetter<string | undefined> | Primary topic or section name. |
wordCount | MaybeRefOrGetter<number | undefined> | Explicit word count (auto-computed from doc.body when omitted). |
siteUrl | MaybeRefOrGetter<string | undefined> | Site URL override (defaults to useSiteConfig().url). |
contributorsPrefix | MaybeRefOrGetter<string | undefined> | Contributors route prefix override. |
contributorsEnabled | MaybeRefOrGetter<boolean | undefined> | Whether contributor profile URLs should be linked. |
useDocSchema(options)
- Provided by:
@nuxtify/cms - Source:
src/runtime/composables/useDocSchema.ts
Reactively registers TechArticle (configurable via content.docs.schemaType) and BreadcrumbList structured data for documentation pages without requiring publishedAt or author.
| Option | Type | Description |
|---|---|---|
doc | MaybeRefOrGetter<Doc | null | undefined> | Documentation page document. |
schemaType | MaybeRefOrGetter<ArticleSchemaType | undefined> | Fallback @type (defaults to content.docs.schemaType or 'TechArticle'). |
breadcrumbs | MaybeRefOrGetter<BreadcrumbItem[] | undefined> | Parent breadcrumb items. |
section | MaybeRefOrGetter<string | undefined> | Active documentation category/section title. |
path | MaybeRefOrGetter<string | undefined> | Public URL path override (useful with custom docs.routePrefix). |
wordCount | MaybeRefOrGetter<number | undefined> | Explicit word count override. |