From 81a3cbea2aedf314e69af6275ade0165454d0ceb Mon Sep 17 00:00:00 2001 From: XPoet Date: Fri, 27 Nov 2020 09:31:10 +0800 Subject: [PATCH] feat: add CDN to load image resources --- layout/article-content.ejs | 2 +- scripts/helpers/helper.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/layout/article-content.ejs b/layout/article-content.ejs index 26e85c8..431bcd5 100644 --- a/layout/article-content.ejs +++ b/layout/article-content.ejs @@ -8,7 +8,7 @@ <% if (theme.base_info.author || config.author) { %>
- <%- image_tag('images/avatar.png') %> + <%- __image_tag('images/avatar.png') %>
diff --git a/scripts/helpers/helper.js b/scripts/helpers/helper.js index c90231c..af03c19 100644 --- a/scripts/helpers/helper.js +++ b/scripts/helpers/helper.js @@ -72,7 +72,6 @@ hexo.extend.helper.register('__css', function (path) { } else { return _css(path); } - }); hexo.extend.helper.register('__favicon_tag', function (path) { @@ -82,6 +81,14 @@ hexo.extend.helper.register('__favicon_tag', function (path) { } else { return _favicon_tag(path); } - +}); + +hexo.extend.helper.register('__image_tag', function (path) { + const _image_tag = hexo.extend.helper.get('image_tag').bind(hexo); + if (this.theme.cdn.enable) { + return `` + } else { + return _image_tag(path); + } });