Skip to content

Commit d9aa1b8

Browse files
committed
处理懒加载图片
1 parent b22acb4 commit d9aa1b8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ const extract = (options) => {
150150
br: false,
151151
// 处理代码块
152152
code: false,
153+
lazyKey: 'data-src',
153154
selectors: {
154155
title: '.article-title',
155156
body: '.markdown-body',
@@ -198,7 +199,8 @@ const extract = (options) => {
198199
const fileName = (getText(selectors.title) || document.title)
199200
const realName = fileName.replace(/[\\\/\?<>:'\*\|]/g, '_')
200201
const files = queryAll('img', markdownBody).map(item => {
201-
const url = item.src.replace(/\?$/, '')
202+
const src = item.getAttribute(options.lazyKey) || item.src
203+
const url = src.replace(/\?$/, '')
202204
const ext = getExt(url)
203205
const name = realName + '/' + md5(url) + (ext ? '.' + ext : '')
204206
item.src = './' + name

0 commit comments

Comments
 (0)