CMS Composables

API reference for content querying, contributor lookup, reading time, Schema.org, and layout composables provided by @nuxtify/cms.

Overview

@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):

  1. Items with draft: true are automatically excluded (where('draft', '=', false)).
  2. If the collection is listed in content.scheduledCollections (or options.filterScheduled is true), items whose publishedAt timestamp 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)

OptionTypeDefaultDescription
filterScheduledbooleanundefinedExplicitly enable (true) or disable (false) future publishedAt filtering for this query, overriding content.scheduledCollections.
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?)

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?)

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?)

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)

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)
ParameterTypeDescription
slugMaybeRefOrGetter<string | undefined>Contributor filename slug (for example, 'jane-doe'). Skips immediate execution when empty.

useReadingTime(article)

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)

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)

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?)

Registers WebPage (or a custom @type such as 'CollectionPage' or 'AboutPage') plus an optional BreadcrumbList for standard pages, collection indexes, and topic hubs.

OptionTypeDescription
typeMaybeRefOrGetter<string | undefined>Override Schema.org WebPage @type (e.g., 'CollectionPage').
breadcrumbsMaybeRefOrGetter<BreadcrumbItem[] | undefined>Parent breadcrumb items; the current page is appended automatically.
headlineMaybeRefOrGetter<string | undefined>Explicit headline / page name fallback.
breadcrumbTitleMaybeRefOrGetter<string | undefined>Concise label for the final breadcrumb item.
descriptionMaybeRefOrGetter<string | undefined>Explicit description fallback.
imageMaybeRefOrGetter<string | undefined>Explicit image path or URL fallback.
pathMaybeRefOrGetter<string | undefined>Explicit current route path for breadcrumb termination.

useArticleSchema(options)

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.

OptionTypeDescription
docMaybeRefOrGetter<Article | Note | null | undefined>Article or note document.
authorMaybeRefOrGetter<Contributor | null | undefined>Resolved contributor record.
authorSlugMaybeRefOrGetter<string | undefined>Contributor slug override (defaults to doc.author).
schemaTypeMaybeRefOrGetter<ArticleSchemaType | undefined>Fallback @type when frontmatter schemaType is omitted.
breadcrumbsMaybeRefOrGetter<BreadcrumbItem[] | undefined>Parent breadcrumb items.
keywordsMaybeRefOrGetter<string[] | undefined>Normalized topic or tag keywords.
sectionMaybeRefOrGetter<string | undefined>Primary topic or section name.
wordCountMaybeRefOrGetter<number | undefined>Explicit word count (auto-computed from doc.body when omitted).
siteUrlMaybeRefOrGetter<string | undefined>Site URL override (defaults to useSiteConfig().url).
contributorsPrefixMaybeRefOrGetter<string | undefined>Contributors route prefix override.
contributorsEnabledMaybeRefOrGetter<boolean | undefined>Whether contributor profile URLs should be linked.

useDocSchema(options)

Reactively registers TechArticle (configurable via content.docs.schemaType) and BreadcrumbList structured data for documentation pages without requiring publishedAt or author.

OptionTypeDescription
docMaybeRefOrGetter<Doc | null | undefined>Documentation page document.
schemaTypeMaybeRefOrGetter<ArticleSchemaType | undefined>Fallback @type (defaults to content.docs.schemaType or 'TechArticle').
breadcrumbsMaybeRefOrGetter<BreadcrumbItem[] | undefined>Parent breadcrumb items.
sectionMaybeRefOrGetter<string | undefined>Active documentation category/section title.
pathMaybeRefOrGetter<string | undefined>Public URL path override (useful with custom docs.routePrefix).
wordCountMaybeRefOrGetter<number | undefined>Explicit word count override.