mirror of https://gitlab.com/curben/blog
refactor(open_graph): drop cheerio and use regex
https://github.com/hexojs/hexo/pull/3680
This commit is contained in:
parent
8c01309128
commit
5f06b4d260
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
const moment = require('moment')
|
const moment = require('moment')
|
||||||
const { escapeHTML, htmlTag, stripHTML } = require('hexo-util')
|
const { escapeHTML, htmlTag, stripHTML } = require('hexo-util')
|
||||||
let cheerio
|
|
||||||
|
|
||||||
function meta (name, content, escape) {
|
function meta (name, content, escape) {
|
||||||
if (escape !== false && typeof content === 'string') {
|
if (escape !== false && typeof content === 'string') {
|
||||||
|
@ -69,13 +68,12 @@ function openGraphHelper (options = {}) {
|
||||||
if (!images.length && content && content.includes('<img')) {
|
if (!images.length && content && content.includes('<img')) {
|
||||||
images = images.slice()
|
images = images.slice()
|
||||||
|
|
||||||
if (!cheerio) cheerio = require('cheerio')
|
// https://github.com/hexojs/hexo/pull/3680
|
||||||
const $ = cheerio.load(content)
|
let img
|
||||||
|
const imgPattern = /<img [^>]*src=['"]([^'"]+)([^>]*>)/gi
|
||||||
$('img').each((index, element) => {
|
while ((img = imgPattern.exec(content)) !== null) {
|
||||||
const src = $(element).attr('data-src')
|
images.push(img[1])
|
||||||
if (src) images.push(src)
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description) {
|
if (description) {
|
||||||
|
|
Loading…
Reference in New Issue