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'
|
||||
let result = ''
|
||||
|
||||
if (!Array.isArray(images)) images = [images]
|
||||
|
||||
if (description) {
|
||||
description = stripHTML(description).substring(0, 200)
|
||||
.trim() // Remove prefixing/trailing spaces
|
||||
|
@ -57,16 +55,6 @@ function openGraphHelper () {
|
|||
.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) {
|
||||
result += meta('description', description)
|
||||
}
|
||||
|
@ -93,6 +81,18 @@ function openGraphHelper () {
|
|||
|
||||
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 => {
|
||||
let url
|
||||
// resolve `path`'s absolute path relative to current page's url
|
||||
|
|
Loading…
Reference in New Issue