diff --git a/README.md b/README.md index 5f2a9ba8..168d7661 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,4 @@ Using Nuxt PWA you can supercharge your current or next Nuxt project with a heav ## License -MIT - Nuxt Community - Pooya Parsa +MIT - Nuxt Community - Pooya Parsa \ No newline at end of file diff --git a/packages/meta/index.js b/packages/meta/index.js index 1313f1b6..45d426a5 100755 --- a/packages/meta/index.js +++ b/packages/meta/index.js @@ -31,7 +31,8 @@ function generateMeta (_options) { lang: 'en', ogType: 'website', ogTitle: true, - ogDescription: true + ogDescription: true, + ogImage: true } // Combine sources @@ -140,6 +141,53 @@ function generateMeta (_options) { if (options.ogDescription && !find(this.options.head.meta, 'property', 'og:description') && !find(this.options.head.meta, 'name', 'og:description')) { this.options.head.meta.push({ hid: 'og:description', name: 'og:description', property: 'og:description', content: options.ogDescription }) } + + // og:image + if (options.ogImage === true) { + if (options.icons && options.icons.length > 0) { + const iconBig = options.icons[options.icons.length - 1] + const [width, height] = iconBig.sizes.split('x').map(x => parseInt(x)) + options.ogImage = {path: iconBig.src, width, height, type: iconBig.type} + } else { + options.ogImage = false + } + } else if (typeof options.ogImage === 'string') { + options.ogImage = {src: options.ogImage} + } + if (options.ogImage && !find(this.options.head.meta, 'property', 'og:image') && !find(this.options.head.meta, 'name', 'og:image')) { + if (options.ogHost) { + this.options.head.meta.push({ + hid: 'og:image', + name: 'og:image', + property: 'og:image', + content: options.ogHost + options.ogImage.path + }) + if (options.ogImage.width && options.ogImage.height) { + this.options.head.meta.push({ + hid: 'og:image:width', + name: 'og:image:width', + property: 'og:image:width', + content: options.ogImage.width + }) + this.options.head.meta.push({ + hid: 'og:image:height', + name: 'og:image:height', + property: 'og:image:height', + content: options.ogImage.height + }) + } + if (options.ogImage.type) { + this.options.head.meta.push({ + hid: 'og:image:type', + name: 'og:image:type', + property: 'og:image:type', + content: options.ogImage.type + }) + } + } else { + debug('No host specified, skipping og:image') + } + } } module.exports.meta = require('./package.json')