提交 29371f4a 编写于 作者: D DCloud_LXH

feat: img loading="lazy"

上级 f9ad09a3
...@@ -80,6 +80,9 @@ const config = { ...@@ -80,6 +80,9 @@ const config = {
.end() .end()
.plugin('normallize-link') .plugin('normallize-link')
.use(require('./markdown/normallizeLink')) .use(require('./markdown/normallizeLink'))
.end()
.plugin('img-attrs')
.use(require('./markdown/markdowm-it-image-attrs'))
} }
}, },
chainWebpack (config, isServer) { chainWebpack (config, isServer) {
......
module.exports = function (md, opts) {
md.core.ruler.after('inline', 'image-attrs', function (state) {
state.tokens.forEach(function (blockToken) {
if (blockToken.type === 'inline' && blockToken.children) {
blockToken.children.forEach(function (token) {
const type = token.type;
if (type === 'image') {
const src = token.attrs.find(attr => attr[0] === 'src');
if (
src &&
src[1].indexOf('qiniu-web-assets.dcloud.net.cn') > -1 &&
token.attrs.map(attr => attr[0]).indexOf('loading') < 0
) {
token.attrs.push(['loading', 'lazy']);
}
}
});
}
});
return false;
});
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册