diff --git a/themes/chameleon/scripts/openGraph.js b/themes/chameleon/scripts/openGraph.js index ee3a93d..7e61770 100644 --- a/themes/chameleon/scripts/openGraph.js +++ b/themes/chameleon/scripts/openGraph.js @@ -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(']*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(']*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