feat(open_graph): remove duplicate twitter tags

- https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup
- prioritise site.config than theme.config
This commit is contained in:
curben 2019-10-18 02:04:31 +01:00
parent 07b342bb27
commit b545b38c1e
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 10 additions and 15 deletions

View File

@ -28,20 +28,19 @@ function og (name, content) {
})}\n` })}\n`
} }
function openGraphHelper (options = {}) { function openGraphHelper () {
const { config, page, theme } = this const { config, page, theme } = this
const { content } = page const { content } = page
let images = page.photos || [] let images = page.photos || []
let description = page.excerpt || theme.description let description = page.excerpt || theme.description || false
const keywords = page.tags || false const keywords = page.tags || false
const title = page.title || theme.nickname const title = page.title || theme.nickname
const type = (this.is_post() ? 'article' : 'website') const type = (this.is_post() ? 'article' : 'website')
const url = encodeURL(this.url) const url = encodeURL(this.url)
const siteName = theme.nickname const siteName = config.subtitle || theme.nickname || false
const twitterCard = options.twitter_card || 'summary'
const published = page.date || false const published = page.date || false
const updated = page.lastUpdated || false const updated = page.lastUpdated || false
const language = options.language || page.lang || page.language || config.language const language = 'en_GB'
let result = '' let result = ''
if (!Array.isArray(images)) images = [images] if (!Array.isArray(images)) images = [images]
@ -80,14 +79,16 @@ function openGraphHelper (options = {}) {
result += og('og:type', type) result += og('og:type', type)
result += og('og:title', title) result += og('og:title', title)
result += og('og:url', url) result += og('og:url', url)
if (siteName) {
result += og('og:site_name', siteName) result += og('og:site_name', siteName)
}
if (description) { if (description) {
result += og('og:description', description) result += og('og:description', description)
} }
if (language) {
result += og('og:locale', language) result += og('og:locale', language)
}
images = images.map(path => { images = images.map(path => {
let url let url
@ -120,12 +121,6 @@ function openGraphHelper (options = {}) {
} }
} }
result += meta('twitter:card', twitterCard)
if (images.length) {
result += meta('twitter:image', images[0])
}
return result.trim() return result.trim()
} }