From c9ba9ed2a2ae811349f79484b620812fb65ee12f Mon Sep 17 00:00:00 2001 From: XPoet Date: Thu, 20 Oct 2022 23:08:07 +0800 Subject: [PATCH] perf(cdn, comment): optimized CDN resource loading for comment plugins --- layout/_partial/comment/gitalk.ejs | 28 ++++-- layout/_partial/comment/twikoo.ejs | 22 ++++- layout/_partial/comment/valine.ejs | 131 ++++++++++++++++------------- layout/_partial/comment/waline.ejs | 36 +++++--- scripts/helpers/helper.js | 3 +- 5 files changed, 139 insertions(+), 81 deletions(-) diff --git a/layout/_partial/comment/gitalk.ejs b/layout/_partial/comment/gitalk.ejs index fc91230..20c14e4 100644 --- a/layout/_partial/comment/gitalk.ejs +++ b/layout/_partial/comment/gitalk.ejs @@ -1,10 +1,27 @@ -<% const { - client_id, +<% +const { + client_id, client_secret, repository, github_id, github_admins -} = theme.comment.gitalk +} = theme.comment?.gitalk +let cdn_css = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.css' +let cdn_js = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js' +const { enable: t_cdn_enable, provider: t_cdn_provider } = theme?.cdn +if (t_cdn_enable === true) { + switch (t_cdn_provider) { + case 'jsdelivr': + cdn_css = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.css' + cdn_js = '//cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js' + break + + case 'unpkg': + cdn_css = '//unpkg.com/gitalk/dist/gitalk.css' + cdn_js = '//unpkg.com/gitalk/dist/gitalk.min.js' + break + } +} %> <% if( @@ -16,9 +33,8 @@ ) { %>
- - + + +
-
<% } %> diff --git a/layout/_partial/comment/waline.ejs b/layout/_partial/comment/waline.ejs index b674642..2917cff 100644 --- a/layout/_partial/comment/waline.ejs +++ b/layout/_partial/comment/waline.ejs @@ -5,22 +5,32 @@ let { version: waline_version, reaction: waline_reaction, } = theme.comment.waline -if (!waline_version) { - waline_version = '2' +if (!waline_version) { waline_version = '2' } +let cdn_css = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline.css` +let cdn_css_meta = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline-meta.css` +let cdn_js = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline.js` +const { enable: t_cdn_enable, provider: t_cdn_provider } = theme?.cdn +if (t_cdn_enable === true) { + switch (t_cdn_provider) { + case 'jsdelivr': + cdn_css = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline.css` + cdn_css_meta = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline-meta.css` + cdn_js = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline.js` + break + + case 'unpkg': + cdn_css = `//unpkg.com/@waline/client@v${waline_version}/dist/waline.css` + cdn_css_meta = `//unpkg.com/@waline/client@v${waline_version}/dist/waline-meta.css` + cdn_js = `//unpkg.com/@waline/client@v${waline_version}/dist/waline.js` + break + } } -const waline_cdn_url = `//cdn.jsdelivr.net/npm/@waline/client@v${waline_version}/dist/waline.js` %> -<% if(theme.comment.use === 'waline' && waline_env_server_url) { %> +<% if(waline_env_server_url) { %>
- - - + + +