Skip to content

Presets

Presets live below your Nuxt source directory in jsonld/:

text
jsonld/
├── types/
├── objects/
└── bundles/

Nested file paths become dot-separated preset names. For example, jsonld/objects/global/website.json is available as global.website.

Type presets

A type preset selects Schema.org classes and creators for Nuxt auto-imports.

json
{
  "description": "Types used by the storefront",
  "types": ["Product", "Offer", "Brand"]
}

Enable the file by its preset name:

ts
export default defineNuxtConfig({
  modules: ['@avensio/nuxt-jsonld'],
  jsonLd: {
    types: ['ecommerce'],
  },
})

You can compose selections with extends, include, and exclude:

json
{
  "extends": ["core"],
  "include": ["Product", "Offer"],
  "exclude": ["Person"]
}

Type presets cannot be loaded through useJsonLdPreset.

Object presets

An object preset contains reusable JSON-LD data:

json
{
  "@type": "WebSite",
  "@id": "https://example.com/#website",
  "name": "Example",
  "url": "https://example.com/"
}

Load it at runtime:

ts
await useJsonLdPreset('global.website')

Or register it application-wide through module configuration:

ts
export default defineNuxtConfig({
  jsonLd: {
    objects: ['global.website'],
  },
})

Bundle presets

A bundle groups object preset names:

json
{
  "description": "Site-wide identities",
  "ids": ["global.website", "global.organization"]
}

Use a bundle at runtime or configure it globally:

ts
await useJsonLdPreset('core')
ts
export default defineNuxtConfig({
  jsonLd: {
    bundles: ['core'],
  },
})

Runtime options

useJsonLdPreset accepts one name or an array of names:

ts
const data = await useJsonLdPreset(['global.website', 'global.organization'], {
  apply: false,
  transform: object => ({ ...object, inLanguage: 'en-US' }),
})
OptionDefaultPurpose
applytrueAdd the resolved objects to the graph.
overwritefalseReplace graph objects with matching @id values.
transform-Transform each resolved object before it is returned or applied.

Use useObjectPresetStore() when you need to inspect presets or register a runtime-only object preset.

Built with VitePress – Released under the MIT License.