style(open_graph): move image-related function to continuous lines

This commit is contained in:
curben 2019-10-18 02:12:43 +01:00
parent 1b6841e9ef
commit d122f5fa6e
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
1 changed files with 12 additions and 12 deletions

View File

@ -44,8 +44,6 @@ function openGraphHelper () {
const language = 'en_GB' const language = 'en_GB'
let result = '' let result = ''
if (!Array.isArray(images)) images = [images]
if (description) { if (description) {
description = stripHTML(description).substring(0, 200) description = stripHTML(description).substring(0, 200)
.trim() // Remove prefixing/trailing spaces .trim() // Remove prefixing/trailing spaces
@ -57,16 +55,6 @@ function openGraphHelper () {
.replace(/\n/g, ' ') // Replace new lines by spaces .replace(/\n/g, ' ') // Replace new lines by spaces
} }
if (!images.length && content && content.includes('<img')) {
images = images.slice()
let img
const imgPattern = /<img [^>]*src=['"]([^'"]+)([^>]*>)/gi
while ((img = imgPattern.exec(content)) !== null) {
images.push(img[1])
}
}
if (description) { if (description) {
result += meta('description', description) result += meta('description', description)
} }
@ -93,6 +81,18 @@ function openGraphHelper () {
result += og('og:locale', language) result += og('og:locale', language)
if (!images.length && content && content.includes('<img')) {
images = images.slice()
let img
const imgPattern = /<img [^>]*src=['"]([^'"]+)([^>]*>)/gi
while ((img = imgPattern.exec(content)) !== null) {
images.push(img[1])
}
}
if (!Array.isArray(images)) images = [images]
images = images.map(path => { images = images.map(path => {
let url let url
// resolve `path`'s absolute path relative to current page's url // resolve `path`'s absolute path relative to current page's url