Skip to content

Commit

Permalink
refactor: vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Jan 12, 2024
1 parent b0ecc05 commit 41942ca
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 78 deletions.
97 changes: 51 additions & 46 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ copyright:
# Sidebar
sidebar: right
widgets:
- category
#- tag
- tagcloud
- archive
- category
#- tag
- tagcloud
- archive
#- recent_posts

# Widget behavior
archive_type: 'monthly'
archive_type: "monthly"
show_count: false
recent_posts_limits: 5

Expand Down Expand Up @@ -77,7 +77,6 @@ social:
# discord: https://discordapp.com/users/yourname
# steam: https://steamcommunity.com/id/yourname


footer:
since: 2020 # 2020-current_year
powered: true
Expand All @@ -91,15 +90,15 @@ math:

# need https://github.com/webappdevelp/hexo-filter-mermaid-diagrams
mermaid: ## mermaid url https://github.com/knsv/mermaid
enable: false # default true
enable: false # default true

# valine comment system. https://valine.js.org
# version 1.5.1
# notify and verify have been deprecated
valine:
enable: false # if you want to use valine,please set this value is true
appId: # leancloud application app id
appKey: # leancloud application app key
appId: # leancloud application app id
appKey: # leancloud application app key
pageSize: 10 # comment list page size
avatar: mp # gravatar style https://valine.js.org/#/avatar
lang: zh-cn # i18n: zh-cn/en
Expand All @@ -112,7 +111,7 @@ valine:
# https://waline.js.org/
waline:
enable: false
serverURL:
serverURL:
lang: zh-CN
locale: {} # https://waline.js.org/guide/features/i18n.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%AD%E8%A8%80
emoji:
Expand All @@ -122,7 +121,7 @@ waline:
- https://unpkg.com/@waline/[email protected]/qq
- https://unpkg.com/@waline/[email protected]/tieba
- https://unpkg.com/@waline/[email protected]/tw-emoji
meta:
meta:
- nick
- mail
- link
Expand All @@ -135,8 +134,8 @@ waline:
# https://twikoo.js.org
twikoo:
enable: false
envId: # 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
region:
envId: # 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
region:

# https://github.com/gitalk/gitalk/blob/master/readme-cn.md
gitalk:
Expand Down Expand Up @@ -201,13 +200,13 @@ dark_mode:
# see https://github.com/D-Sketon/mouse-firework
firework:
enable: true
options:
options:
excludeElements: ["a"]
particles:
- shape: circle
move: ["emit"]
easing: easeOutExpo
colors: ["#ff5252","#ff7c7c","#ffafaf","#ffd0d0"]
colors: ["#ff5252", "#ff7c7c", "#ffafaf", "#ffd0d0"]
number: 20
duration: [1200, 1800]
shapeOptions:
Expand Down Expand Up @@ -238,38 +237,44 @@ live2d:

# Dependent cdn links
vendor:
cdn_jsdelivr_gh: https://cdn.jsdelivr.net/gh/
cdn_jsdelivr_npm: https://cdn.jsdelivr.net/npm/
fastly_jsdelivr_gh: https://fastly.jsdelivr.net/gh/
fastly_jsdelivr_npm: https://fastly.jsdelivr.net/npm/
unpkg: https://unpkg.com/
webcache: https://npm.webcache.cn/
js:
jquery: https://unpkg.com/[email protected]/dist/jquery.min.js
clipboard: https://unpkg.com/[email protected]/dist/clipboard.min.js
lazysizes: https://unpkg.com/[email protected]/lazysizes.min.js
fancybox: https://unpkg.com/@fancyapps/[email protected]/dist/jquery.fancybox.min.js
valine: https://unpkg.com/[email protected]/dist/Valine.min.js
waline: https://unpkg.com/@waline/client@v2/dist/waline.mjs
twikoo: https://unpkg.com/[email protected]/dist/twikoo.all.min.js
gitalk: https://unpkg.com/gitalk/dist/gitalk.min.js
busuanzi: https://unpkg.com/[email protected]/bsz.pure.mini.js
algolia: https://unpkg.com/[email protected]/dist/algoliasearch-lite.umd.js
instantsearch: https://unpkg.com/[email protected]/dist/instantsearch.production.min.js
pace: https://unpkg.com/[email protected]/pace.min.js
mermaid: https://unpkg.com/[email protected]/dist/mermaid.min.js
wow: https://unpkg.com/[email protected]/dist/wow.min.js
firework: https://www.unpkg.com/[email protected]/dist/index.umd.js
pjax: https://www.unpkg.com/[email protected]/dist/index.umd.js
live2d:
base: https://fastly.jsdelivr.net/gh/MliKiowa/plugin-live2d/
js: https://fastly.jsdelivr.net/gh/MliKiowa/plugin-live2d/js/live2d-autoload.js
jquery: webcache|[email protected]/dist/jquery.min.js
clipboard: webcache|[email protected]/dist/clipboard.min.js
lazysizes: webcache|[email protected]/lazysizes.min.js
fancybox: webcache|@fancyapps/[email protected]/dist/jquery.fancybox.min.js
valine: webcache|[email protected]/dist/Valine.min.js
waline: webcache|@waline/client@v2/dist/waline.mjs
twikoo: webcache|[email protected]/dist/twikoo.all.min.js
gitalk: webcache|gitalk/dist/gitalk.min.js
busuanzi: webcache|[email protected]/bsz.pure.mini.js
algolia: webcache|[email protected]/dist/algoliasearch-lite.umd.js
instantsearch: webcache|[email protected]/dist/instantsearch.production.min.js
pace: webcache|[email protected]/pace.min.js
mermaid: webcache|[email protected]/dist/mermaid.min.js
wow: webcache|[email protected]/dist/wow.min.js
firework: webcache|[email protected]/dist/index.umd.js
pjax: webcache|[email protected]/dist/index.umd.js
live2d:
base: fastly_jsdelivr_gh|MliKiowa/plugin-live2d/
js: fastly_jsdelivr_gh|MliKiowa/plugin-live2d/js/live2d-autoload.js
css:
highlight: https://unpkg.com/[email protected]/index.css
fancybox: https://unpkg.com/@fancyapps/[email protected]/dist/jquery.fancybox.min.css
katex: https://unpkg.com/[email protected]/dist/katex.min.css
waline: https://unpkg.com/@waline/client@v2/dist/waline.css
gitalk: https://unpkg.com/gitalk/dist/gitalk.css
fontawesome:
highlight: webcache|[email protected]/index.css
fancybox: webcache|@fancyapps/[email protected]/dist/jquery.fancybox.min.css
katex: webcache|[email protected]/dist/katex.min.css
waline: webcache|@waline/client@v2/dist/waline.css
gitalk: webcache|gitalk/dist/gitalk.css
fontawesome:
high_priority:
- https://unpkg.com/@fortawesome/[email protected]/css/regular.min.css
- https://unpkg.com/@fortawesome/[email protected]/css/solid.min.css
- webcache|@fortawesome/[email protected]/css/regular.min.css
- webcache|@fortawesome/[email protected]/css/solid.min.css
low_priority:
- https://unpkg.com/@fortawesome/[email protected]/css/brands.min.css
- https://unpkg.com/@fortawesome/[email protected]/css/v5-font-face.min.css
- https://unpkg.com/@fortawesome/[email protected]/css/v4-font-face.min.css
animate: https://unpkg.com/[email protected]/css/libs/animate.css
- webcache|@fortawesome/[email protected]/css/brands.min.css
- webcache|@fortawesome/[email protected]/css/v5-font-face.min.css
- webcache|@fortawesome/[email protected]/css/v4-font-face.min.css
animate: webcache|[email protected]/css/libs/animate.css
44 changes: 22 additions & 22 deletions layout/_partial/after-footer.ejs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<%- js(theme.vendor.js.jquery) %>
<%- js(theme.vendor.js.lazysizes) %>
<%- js(theme.vendor.js.clipboard) %>
<%- js(vendorCdn(theme.vendor.js.jquery)) %>
<%- js(vendorCdn(theme.vendor.js.lazysizes)) %>
<%- js(vendorCdn(theme.vendor.js.clipboard)) %>

<% if (theme.fancybox) { %>
<%- js(theme.vendor.js.fancybox) %>
<%- js({src: vendorCdn(theme.vendor.js.fancybox)[0], defer: true}) %>
<% } %>
<% if (theme.footer.busuanzi) { %>
<%- js({src: theme.vendor.js.busuanzi, defer: true}) %>
<%- js({src: vendorCdn(theme.vendor.js.busuanzi)[0], async: true}) %>
<% } %>

<%- copyright() %>

<% if (theme.mermaid.enable) { %>
<%- js(theme.vendor.js.mermaid) %>
<%- js(vendorCdn(theme.vendor.js.mermaid)) %>
<script>
if (window.mermaid) {
// https://github.com/mermaid-js/mermaid/issues/1945
Expand Down Expand Up @@ -80,7 +78,7 @@
<%- partial('analytics/gauges-analytics') %>

<% if (theme.valine.enable && theme.valine.appId && theme.valine.appKey) { %>
<%- js({src: theme.vendor.js.valine, 'data-pjax': true}) %>
<%- js({src: vendorCdn(theme.vendor.js.valine)[0], 'data-pjax': true}) %>
<script data-pjax>
var GUEST_INFO = ['nick', 'mail', 'link'];
var guest_info = '<%= theme.valine.guest_info %>'.split(',').filter((item) => {
Expand All @@ -107,9 +105,9 @@
<% } %>

<% if (theme.waline.enable && theme.waline.serverURL) { %>
<%- js({src: theme.vendor.js.valine, 'data-pjax': true}) %>
<%- js({src: vendorCdn(theme.vendor.js.waline)[0], 'data-pjax': true}) %>
<script data-pjax type="module">
import { init } from "<%= theme.vendor.js.waline %>";
import { init } from "<%= vendorCdn(theme.vendor.js.waline)[0] %>";
init({
el: '.wcomment',
serverURL: '<%= theme.waline.serverURL %>',
Expand All @@ -127,7 +125,7 @@
<% } %>

<% if (theme.gitalk.enable && theme.gitalk.clientID && theme.gitalk.clientSecret) { %>
<%- js({src: theme.vendor.js.gitalk, 'data-pjax': true}) %>
<%- js({src: vendorCdn(theme.vendor.js.gitalk)[0], 'data-pjax': true}) %>
<script data-pjax>
const gitalk = new Gitalk({
clientID: '<%= theme.gitalk.clientID %>',
Expand All @@ -143,7 +141,7 @@
<% } %>

<% if (theme.twikoo.enable && theme.twikoo.envId) { %>
<%- js({src: theme.vendor.js.twikoo, 'data-pjax': true}) %>
<%- js({src: vendorCdn(theme.vendor.js.twikoo)[0], 'data-pjax': true}) %>
<script data-pjax>
twikoo.init({
envId: '<%= theme.twikoo.envId %>',
Expand Down Expand Up @@ -174,12 +172,12 @@

<% if (theme.generator_search.enable) { %>
<%- js('js/generator_search.js') %>
<%- js(theme.vendor.js.instantsearch) %>
<%- js(vendorCdn(theme.vendor.js.instantsearch)) %>
<% } %>

<% if (theme.algolia_search.enable) { %>
<%- js(theme.vendor.js.algolia) %>
<%- js(theme.vendor.js.instantsearch) %>
<%- js(vendorCdn(theme.vendor.js.algolia)) %>
<%- js(vendorCdn(theme.vendor.js.instantsearch)) %>
<%- js('js/algolia_search.js') %>
<script>
var CONFIG = {
Expand All @@ -202,14 +200,14 @@
<% } %>

<% if (theme.firework.enable) { %>
<%- js(theme.vendor.js.firework) %>
<%- js(vendorCdn(theme.vendor.js.firework)) %>
<script>
firework(JSON.parse('<%- JSON.stringify(theme.firework.options) %>'))
</script>
<% } %>

<% if (theme.pjax.enable) { %>
<%- js(theme.vendor.js.pjax) %>
<%- js(vendorCdn(theme.vendor.js.pjax)) %>
<script>
new Pjax({
selectors: [
Expand Down Expand Up @@ -258,12 +256,14 @@
<% } %>

<% if (theme.live2d.enable) { %>
<%- js(theme.vendor.js.live2d.js) %>
<script>
live2d.init("<%- theme.vendor.js.live2d.base %>", {
themeTipsPath: ""
});
function initLive2d() {
live2d.init("<%- vendorCdn(theme.vendor.js.live2d.base)[0] %>", {themeTipsPath: ""});
}
</script>
<%- js({src: vendorCdn(theme.vendor.js.live2d.js)[0], onload: "initLive2d && initLive2d()", async: true})%>
<% } %>

<%- js('js/script.js') %>

<%- copyright() %>
20 changes: 10 additions & 10 deletions layout/_partial/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<%- vendorFont(site) %>
<%- css(theme.vendor.css.fontawesome.high_priority) %>
<%- preloadStyle(theme.vendor.css.fontawesome.low_priority) %>
<%- css(vendorCdn(theme.vendor.css.fontawesome.high_priority)) %>
<%- preloadStyle(vendorCdn(theme.vendor.css.fontawesome.low_priority)) %>
<%- css('css/loader') %>
<%- open_graph({twitter_id: theme.twitter, fb_admins: theme.fb_admins, fb_app_id: theme.fb_app_id}) %>
<% if (config.feed) { %>
Expand All @@ -37,25 +37,25 @@
<%- favicon_tag(theme.favicon) %>
<% } %>
<% if (config.highlight.enable) { %>
<%- css(theme.vendor.css.highlight) %>
<%- css(vendorCdn(theme.vendor.css.highlight)) %>
<% } %>
<%- css('css/style') %>
<% if (theme.fancybox) { %>
<%- css(theme.vendor.css.fancybox) %>
<%- css(vendorCdn(theme.vendor.css.fancybox)) %>
<% } %>
<% if (theme.math.enable) { %>
<%- css(theme.vendor.css.katex) %>
<%- css(vendorCdn(theme.vendor.css.katex)) %>
<% } %>
<% if (theme.waline.enable && theme.waline.serverURL) { %>
<%- css(theme.vendor.css.waline) %>
<%- css(vendorCdn(theme.vendor.css.waline)) %>
<% } %>
<% if (theme.gitalk.enable && theme.gitalk.clientID && theme.gitalk.clientSecret) { %>
<%- css(theme.vendor.css.gitalk) %>
<%- css(vendorCdn(theme.vendor.css.gitalk)) %>
<% } %>
<%- js(theme.vendor.js.pace)%>
<%- js(vendorCdn(theme.vendor.js.pace)) %>
<% if (theme.animation.enable) { %>
<%- css(theme.vendor.css.animate) %>
<%- js(theme.vendor.js.wow)%>
<%- css(vendorCdn(theme.vendor.css.animate)) %>
<%- js(vendorCdn(theme.vendor.js.wow)) %>
<script>
new WOW({
offset: 0,
Expand Down
16 changes: 16 additions & 0 deletions scripts/helper/vendorCdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
hexo.extend.helper.register('vendorCdn', (content) => {
if (!Array.isArray(content)) {
content = [content]
}
return content.map(item => {
const contentToken = item.split('|')
if (contentToken.length !== 2) {
throw new Error("invalid vendor")
}
const cdn = contentToken[0]
if (!hexo.theme.config.vendor[cdn]) {
throw new Error("invalid cdn")
}
return hexo.theme.config.vendor[cdn] + contentToken[1]
})
})
File renamed without changes.

0 comments on commit 41942ca

Please sign in to comment.