From a605e11c851e014bc5d2cca14c7f3e77e872bf0f Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 30 Jun 2020 14:00:46 +0800 Subject: [PATCH 1/3] feat: lazyload --- index.js | 1 + lib/renderer.js | 1 + test/index.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/index.js b/index.js index 698f6a7..62662ad 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ hexo.config.marked = Object.assign({ headerIds: true, // TODO: enable prependRoot by default in v3 prependRoot: false, + lazyload: false, external_link: { enable: false, exclude: [], diff --git a/lib/renderer.js b/lib/renderer.js index ed8900f..a0c9d3f 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -93,6 +93,7 @@ class Renderer extends MarkedRenderer { let out = `${text} { ].join('\n')); }); + it('lazyload image', () => { + const body = [ + '![](/bar/baz.jpg)', + '![foo](/aaa/bbb.jpg)' + ].join('\n'); + + ctx.config.marked.lazyload = true; + + const r = require('../lib/renderer').bind(ctx); + + const result = r({ text: body }); + + result.should.eql([ + '

', + 'foo

\n' + ].join('\n')); + }); + describe('exec filter to extend', () => { it('should execute filter registered to marked:renderer', () => { const hexo = new Hexo(__dirname, {silent: true}); From 6401d0bbcac64709d90f6c209225774fe220c2c1 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 30 Jun 2020 14:49:19 +0800 Subject: [PATCH 2/3] Update renderer.js --- lib/renderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/renderer.js b/lib/renderer.js index a0c9d3f..0ca933d 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -93,7 +93,7 @@ class Renderer extends MarkedRenderer { let out = `${text} Date: Tue, 30 Jun 2020 22:55:17 +0800 Subject: [PATCH 3/3] Update docs --- README.md | 2 ++ index.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ed921e3..7b824b7 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ marked: autolink: true sanitizeUrl: false headerIds: true + lazyload: false prependRoot: false external_link: enable: false @@ -47,6 +48,7 @@ marked: - **autolink** - Enable autolink for URLs. E.g. `https://hexo.io` will become `https://hexo.io`. - **sanitizeUrl** - Remove URLs that start with `javascript:`, `vbscript:` and `data:`. - **headerIds** - Insert header id, e.g. `

text

`. Useful for inserting anchor link to each paragraph with a heading. +- **lazyload** - Lazy loading images via `loading="lazy"` attribute. - **prependRoot** - Prepend root value to (internal) image path. * Example `_config.yml`: ``` yml diff --git a/index.js b/index.js index 62662ad..4a82c9b 100644 --- a/index.js +++ b/index.js @@ -14,9 +14,9 @@ hexo.config.marked = Object.assign({ autolink: true, sanitizeUrl: false, headerIds: true, + lazyload: false, // TODO: enable prependRoot by default in v3 prependRoot: false, - lazyload: false, external_link: { enable: false, exclude: [],