@nuxtjs/meta
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -6,2 +6,14 @@ # Change Log | ||
<a name="2.1.0"></a> | ||
# [2.1.0](https://github.com/nuxt-community/pwa-module/compare/@nuxtjs/meta@2.0.2...@nuxtjs/meta@2.1.0) (2018-03-05) | ||
### Features | ||
* add og:image support ([#30](https://github.com/nuxt-community/pwa-module/issues/30)) ([afebd96](https://github.com/nuxt-community/pwa-module/commit/afebd96)) | ||
<a name="2.0.2"></a> | ||
@@ -8,0 +20,0 @@ ## [2.0.2](https://github.com/nuxt-community/pwa-module/compare/@nuxtjs/meta@2.0.1...@nuxtjs/meta@2.0.2) (2017-12-29) |
50
index.js
@@ -34,3 +34,4 @@ const debug = require('debug')('nuxt:pwa') | ||
ogTitle: true, | ||
ogDescription: true | ||
ogDescription: true, | ||
ogImage: true | ||
} | ||
@@ -144,4 +145,51 @@ | ||
} | ||
// 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') |
{ | ||
"name": "@nuxtjs/meta", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
12016
166