Skip to content

Commit

Permalink
Merge pull request #7 from srk4393/JSOND
Browse files Browse the repository at this point in the history
Added support for structured data (e.g. "schema.org") via the "json-ld" script tag in the head
  • Loading branch information
nickfrosty committed Dec 21, 2021
2 parents 9e970ca + c69fa6b commit 849947e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package/lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const allMetas = {
type: {id: 'card', content: true},
site: {content: true},
creator: {content: true}
}
},
jsonld: {content: false}
}

allMetas.openGraph.images = allMetas.openGraph.image
Expand Down Expand Up @@ -242,6 +243,8 @@ const createCanonical = (options, path) => {
]
}



module.exports = function (moduleOptions) {
if (!moduleOptions.meta) {
moduleOptions.meta = {}
Expand Down Expand Up @@ -295,4 +298,4 @@ module.exports.defaults = defaults
module.exports.createTitle = createTitle
module.exports.createMeta = createMeta
module.exports.createCanonical = createCanonical
module.exports.template = allMetas
module.exports.template = allMetas
10 changes: 10 additions & 0 deletions package/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export default function (ctx, inject) {

ctx.app.head.title = nuxtSeo.createTitle(options)
ctx.app.head.meta = nuxtSeo.createMeta(options, ctx.app.head.meta, template)


if (ctx.route && ctx.route.path) {
ctx.app.head.link = nuxtSeo.createCanonical(options, ctx.route.path)
}
Expand All @@ -23,6 +25,14 @@ export default function (ctx, inject) {
ctx.app.context.app.head = ctx.app.head
}

if(options.jsonld){
ctx.app.head.script.push({
vmid: 'ldjson-schema',
json: options.jsonld,
type: 'application/ld+json'
});
}

try {
if (Vue.prototype && Vue.prototype.$meta) { // Vue-meta is enabled
if (this.$nuxt && this.$nuxt.$options && this.$nuxt.$options.head) {
Expand Down

0 comments on commit 849947e

Please sign in to comment.