Skip to content

Commit

Permalink
waline: change to local #247
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanNotFound committed Sep 30, 2023
1 parent 2271667 commit 6947218
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
2 changes: 1 addition & 1 deletion layout/_partials/comments/waline.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div id="waline"></div>
<script type="module" <%= theme.global.single_page === true ? 'data-swup-reload-script' : '' %>>
import { init } from 'https://evan.beee.top/js/waline.mjs';
import { init } from '<%= renderJSPath('js/libs/waline.mjs') %>';
function loadWaline() {
init({
Expand Down
14 changes: 7 additions & 7 deletions layout/_partials/scripts.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%- renderModuleJS([
<%- renderJSModule([
'js/utils.js',
'js/main.js',
'js/layouts/navbarShrink.js',
Expand All @@ -8,15 +8,15 @@
]) %>

<% if (theme.navbar.search.enable) { %>
<%- renderModuleJS('js/tools/localSearch.js') %>
<%- renderJSModule('js/tools/localSearch.js') %>
<% } %>

<% if (theme.articles.code_block.copy) { %>
<%- renderModuleJS('js/tools/codeBlock.js') %>
<%- renderJSModule('js/tools/codeBlock.js') %>
<% } %>

<% if (theme.articles.lazyload) { %>
<%- renderModuleJS('js/layouts/lazyload.js') %>
<%- renderJSModule('js/layouts/lazyload.js') %>
<% } %>

<% if (theme.footer.runtime) { %>
Expand All @@ -27,7 +27,7 @@

<% if (theme.home_banner.subtitle.length !== 0) { %>
<%- renderJS('js/libs/Typed.min.js') %>
<%- renderModuleJS('js/plugins/typed.js') %>
<%- renderJSModule('js/plugins/typed.js') %>
<% } %>

<% if (theme.plugins.mermaid.enable) { %>
Expand All @@ -37,14 +37,14 @@

<% if (theme.masonry || theme.photos || theme.gallery) { %>
<%- renderJS('js/libs/minimasonry.min.js') %>
<%- renderModuleJS('js/plugins/masonry.js') %>
<%- renderJSModule('js/plugins/masonry.js') %>
<% } %>

<div class="post-scripts" <%= theme.global.single_page === true ? 'data-swup-reload-script' : '' %>>
<% if (theme.articles.toc.enable) { %>
<%- renderJS('js/libs/anime.min.js')%>
<%- renderModuleJS([
<%- renderJSModule([
'js/tools/tocToggle.js',
'js/layouts/toc.js',
'js/plugins/tabs.js'
Expand Down
50 changes: 49 additions & 1 deletion scripts/helpers/themeHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ hexo.extend.helper.register("renderJS", function (path) {
return t;
});

hexo.extend.helper.register("renderModuleJS", function (path) {
hexo.extend.helper.register("renderJSModule", function (path) {
const _js = hexo.extend.helper.get("js").bind(hexo);
const cdnProviders = {
staticfile: "https://cdn.staticfile.org",
Expand Down Expand Up @@ -188,6 +188,54 @@ hexo.extend.helper.register("renderModuleJS", function (path) {
return t;
});

hexo.extend.helper.register("renderJSPath", function (path) {
const _url_for = hexo.extend.helper.get("url_for").bind(hexo);
const cdnProviders = {
staticfile: "https://cdn.staticfile.org",
bootcdn: "https://cdn.bootcdn.net/ajax/libs",
cdnjs: "https://cdnjs.cloudflare.com/ajax/libs",
unpkg: "https://unpkg.com",
jsdelivr: "https://cdn.jsdelivr.net/npm",
aliyun: "https://evan.beee.top/projects",
custom: this.theme.cdn.custom_url,
};

const cdnPathHandle = (path) => {
const cdnBase =
cdnProviders[this.theme.cdn.provider] || cdnProviders.staticfile;
if (this.theme.cdn.provider === "custom") {
const customUrl = cdnBase
.replace("${version}", themeVersion)
.replace("${path}", path);
return this.theme.cdn.enable ? customUrl : _url_for(path);
} else if (
this.theme.cdn.provider === "staticfile" ||
this.theme.cdn.provider === "bootcdn" ||
this.theme.cdn.provider === "cdnjs"
) {
return this.theme.cdn.enable
? `${cdnBase}/hexo-theme-redefine/${themeVersion}/${path}`
: _url_for(path);
} else {
return this.theme.cdn.enable
? `${cdnBase}/hexo-theme-redefine@${themeVersion}/source/${path}`
: _url_for(path);
}
};

let t = "";

if (Array.isArray(path)) {
for (const p of path) {
t += cdnPathHandle(p);
}
} else {
t = cdnPathHandle(path);
}

return t;
});

hexo.extend.helper.register("renderCSS", function (path) {
const _css = hexo.extend.helper.get("css").bind(hexo);
const cdnProviders = {
Expand Down
2 changes: 2 additions & 0 deletions source/js/libs/waline.mjs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions source/js/libs/waline.mjs.map

Large diffs are not rendered by default.

0 comments on commit 6947218

Please sign in to comment.