X Enterprises
Composables

useSchema

Shared utilities for Schema.org JSON-LD injection, URL resolution, and app.config defaults for publisher and organizer objects.

useSchema

Internal composable shared by all XSchema* components. Provides URL resolution helpers, default organization/publisher objects sourced from app.config.ts, author/image normalisation utilities, and useSchemaHead() — the function that injects a <script type="application/ld+json"> tag into <head> via useHead. You can also call it directly to inject arbitrary JSON-LD from your own components or pages.

Usage

const {
  siteUrl,
  siteName,
  resolveUrl,
  getDefaultOrganization,
  getDefaultPublisher,
  normalizeAuthor,
  normalizeImage,
  useSchemaHead,
} = useSchema()

Returns

KeyTypeDescription
siteUrlComputedRef<string>Configured site URL from app.config.ts with no trailing slash.
siteNameComputedRef<string>Configured site name from app.config.ts.
resolveUrl(path)string | undefinedConverts a relative path to an absolute URL using siteUrl. Returns undefined if path is falsy.
getDefaultOrganization()OrganizationReturns a Schema.org Organization object built from xSchema.organizationName, xSchema.siteUrl, and xSchema.siteLogo.
getDefaultPublisher()objectReturns a Schema.org publisher object with an ImageObject logo, suitable for Article and BlogPosting schemas.
normalizeAuthor(author)Person | Person[] | undefinedConverts a string name, a Person object, or an array of either into a correctly typed Schema.org Person array.
normalizeImage(image)string[] | undefinedEnsures an image value (string or array) is always returned as an array. Returns undefined if falsy.
useSchemaHead(fn)voidCalls fn() to get a JSON-LD object, then injects it as a <script type="application/ld+json"> tag into <head> via useHead. SSR-safe — rendered server-side on first paint.

AI Context

composable: useSchema
package: "@xenterprises/nuxt-x-schema"
use-when: >
  Injecting custom Schema.org JSON-LD into a Nuxt page when none of the
  16 pre-built XSchema* components fit your use case. Call useSchemaHead()
  with a function that returns your JSON-LD object. Also use resolveUrl()
  to convert relative paths to absolute URLs, and getDefaultPublisher() /
  getDefaultOrganization() to pull branding from app.config.ts rather than
  hardcoding it. All XSchema* components use this composable internally —
  you rarely need it unless building a custom schema component.
Copyright © 2026