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 { escapeHTML, htmlTag, stripHTML } = require('hexo-util')
|
||||
let cheerio
|
||||
|
||||
function meta (name, content, escape) {
|
||||
if (escape !== false && typeof content === 'string') {
|
||||
|
@ -69,13 +68,12 @@ function openGraphHelper (options = {}) {
|
|||
if (!images.length && content && content.includes('<img')) {
|
||||
images = images.slice()
|
||||
|
||||
if (!cheerio) cheerio = require('cheerio')
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
$('img').each((index, element) => {
|
||||
const src = $(element).attr('data-src')
|
||||
if (src) images.push(src)
|
||||
})
|
||||
// https://github.com/hexojs/hexo/pull/3680
|
||||
let img
|
||||
const imgPattern = /<img [^>]*src=['"]([^'"]+)([^>]*>)/gi
|
||||
while ((img = imgPattern.exec(content)) !== null) {
|
||||
images.push(img[1])
|
||||
}
|
||||
}
|
||||
|
||||
if (description) {
|
||||
|
|
Loading…
Reference in New Issue