mirror of https://gitlab.com/curben/blog
style(open_graph): move image-related function to continuous lines
This commit is contained in:
parent
1b6841e9ef
commit
d122f5fa6e
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue