Presets
Presets live below your Nuxt source directory in jsonld/:
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.
{
"description": "Types used by the storefront",
"types": ["Product", "Offer", "Brand"]
}Enable the file by its preset name:
export default defineNuxtConfig({
modules: ['@avensio/nuxt-jsonld'],
jsonLd: {
types: ['ecommerce'],
},
})You can compose selections with extends, include, and exclude:
{
"extends": ["core"],
"include": ["Product", "Offer"],
"exclude": ["Person"]
}Type presets cannot be loaded through useJsonLdPreset.
Object presets
An object preset contains reusable JSON-LD data:
{
"@type": "WebSite",
"@id": "https://example.com/#website",
"name": "Example",
"url": "https://example.com/"
}Load it at runtime:
await useJsonLdPreset('global.website')Or register it application-wide through module configuration:
export default defineNuxtConfig({
jsonLd: {
objects: ['global.website'],
},
})Bundle presets
A bundle groups object preset names:
{
"description": "Site-wide identities",
"ids": ["global.website", "global.organization"]
}Use a bundle at runtime or configure it globally:
await useJsonLdPreset('core')export default defineNuxtConfig({
jsonLd: {
bundles: ['core'],
},
})Runtime options
useJsonLdPreset accepts one name or an array of names:
const data = await useJsonLdPreset(['global.website', 'global.organization'], {
apply: false,
transform: object => ({ ...object, inLanguage: 'en-US' }),
})| Option | Default | Purpose |
|---|---|---|
apply | true | Add the resolved objects to the graph. |
overwrite | false | Replace 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.