From 4b8a610c086dc199cb42ff674364a77f960e492a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E6=A2=A6?= <68908911+icemyst@users.noreply.github.com> Date: Thu, 20 Feb 2025 14:10:13 +0800 Subject: [PATCH 1/4] Update pjax.pug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 自定义404.html跳转更平滑,使用 window.location.href = e.request.responseURL 加载,自定义404.html加载速度缓慢,可能会出现loading二次加载 --- layout/includes/third-party/pjax.pug | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/layout/includes/third-party/pjax.pug b/layout/includes/third-party/pjax.pug index a8094f1..94ec038 100644 --- a/layout/includes/third-party/pjax.pug +++ b/layout/includes/third-party/pjax.pug @@ -59,7 +59,10 @@ script. document.addEventListener('pjax:error', e => { if (e.request.status === 404) { - window.location.href = e.request.responseURL + const usePjax = !{theme.pjax && theme.pjax.enable} + !{theme.error_404 && theme.error_404.enable} + ? (usePjax ? pjax.loadUrl('!{url_for("/404.html")}') : window.location.href = '!{url_for("/404.html")}') + : window.location.href = e.request.responseURL } }) - })() \ No newline at end of file + })() From 2de7d34b2b642ccfda2f22e0b9dbb177fd74aa39 Mon Sep 17 00:00:00 2001 From: Yuchen Mu <2012026@mail.nankai.edu.cn> Date: Mon, 24 Feb 2025 19:03:46 +0800 Subject: [PATCH 2/4] feat(score tag): support RenderAbc options Modified the score tag to pass custom options to the abcjs RenderAbc interface. This enhancement enables proper rendering of guitar tablature with custom settings such as instrument tuning, labels, and formatting options. --- layout/includes/third-party/abcjs/abcjs.pug | 64 ++++++++++++++++----- scripts/tag/score.js | 34 ++++++++++- 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/layout/includes/third-party/abcjs/abcjs.pug b/layout/includes/third-party/abcjs/abcjs.pug index 453f84b..45d6924 100644 --- a/layout/includes/third-party/abcjs/abcjs.pug +++ b/layout/includes/third-party/abcjs/abcjs.pug @@ -1,17 +1,51 @@ script. - (() => { - const abcjsInit = () => { - const abcjsFn = () => setTimeout(() => { - document.querySelectorAll(".abc-music-sheet").forEach(ele => { - if (ele.children.length > 0) return - ABCJS.renderAbc(ele, ele.innerHTML, {responsive: 'resize'}) - }) - }, 100) - - typeof ABCJS === 'object' ? abcjsFn() - : btf.getScript('!{url_for(theme.asset.abcjs_basic_js)}').then(abcjsFn) - } + (function() { + var abcjsInit = function() { + var abcjsFn = function() { + setTimeout(function() { + var sheets = document.querySelectorAll(".abc-music-sheet"); + for (var i = 0; i < sheets.length; i++) { + var ele = sheets[i]; + if (ele.children.length > 0) continue; + + // 从 data-params 属性中解析参数 + var params = {}; + var dp = ele.getAttribute("data-params"); + if (dp) { + try { + params = JSON.parse(dp); + } catch (e) { + console.error("解析 data-params 失败:", e); + } + } + + // 将解析出的参数与 responsive 参数合并, + // 保证 params 中的内容在 responsive 之前 + var options = {}; + for (var key in params) { + if (params.hasOwnProperty(key)) { + options[key] = params[key]; + } + } + options.responsive = "resize"; + + // 使用 ABCJS.renderAbc 渲染乐谱 + ABCJS.renderAbc(ele, ele.innerHTML, options); + } + }, 100); + }; - window.pjax ? abcjsInit() : window.addEventListener('load', abcjsInit) - btf.addGlobalFn('encrypt', abcjsInit, 'abcjs') - })() \ No newline at end of file + if (typeof ABCJS === "object") { + abcjsFn(); + } else { + btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn); + } + }; + + if (window.pjax) { + abcjsInit(); + } else { + window.addEventListener("load", abcjsInit); + } + btf.addGlobalFn("encrypt", abcjsInit, "abcjs"); + })(); \ No newline at end of file diff --git a/scripts/tag/score.js b/scripts/tag/score.js index dc380a5..f4add38 100644 --- a/scripts/tag/score.js +++ b/scripts/tag/score.js @@ -6,17 +6,45 @@ 'use strict' const score = (args, content) => { + // 转义 HTML 标签和部分特殊字符,包括花括号 const escapeHtmlTags = s => { const lookup = { '&': '&', '"': '"', '\'': ''', '<': '<', - '>': '>' + '>': '>', + '{': '{', + '}': '}' } - return s.replace(/[&"'<>]/g, c => lookup[c]) + return s.replace(/[&"'<>{}]/g, c => lookup[c]) } - return `
(.*?)<\/p>/g + const result = reg.exec(data) + if (result && result[1]) { + typedJSFn.processSubtitle(result[1]) + } else { + throw new Error('Failed to parse the return value of the Yiyan API') + } + }) + .catch(err => { + console.error('Failed to get the Yiyan API:', err) + typedJSFn.processSubtitle(!{JSON.stringify(subContent.length)}) + }) } typedJSFn.run(subtitleType) when 3 script. function subtitleType () { - btf.getScript('https://sdk.jinrishici.com/v2/browser/jinrishici.js').then(() => { - jinrishici.load(result =>{ - if (!{effect}) { - const sub = !{JSON.stringify(subContent)} - const content = result.data.content - sub.unshift(content) - typedJSFn.init(sub) - } else { - document.getElementById('subtitle').textContent = result.data.content - } + btf.getScript('https://sdk.jinrishi8ci.com/v2/browser/jinrishici.js') + .then(() => { + jinrishici.load(result => { + if (result && result.data && result.data.content) { + typedJSFn.processSubtitle(result.data.content) + } else { + throw new Error('Failed to parse the return value of Jinrishici API') + } + }) + }) + .catch(err => { + console.error('Failed to get the Jinrishici API:', err) + typedJSFn.processSubtitle(!{JSON.stringify(subContent.length)}) }) - }) } typedJSFn.run(subtitleType) default - - subContent = subContent.length ? subContent : new Array(config.subtitle) - script. - function subtitleType () { - if (!{effect}) { - typedJSFn.init(!{JSON.stringify(subContent)}) - } else { - document.getElementById("subtitle").textContent = !{JSON.stringify(subContent[0])} + if subContent.length > 0 + script. + function subtitleType () { + typedJSFn.processSubtitle(!{JSON.stringify(subContent)}) } - } - typedJSFn.run(subtitleType) \ No newline at end of file + typedJSFn.run(subtitleType) \ No newline at end of file diff --git a/package.json b/package.json index 27543bf..4db56e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-theme-butterfly", - "version": "5.3.3", + "version": "5.3.4", "description": "A Simple and Card UI Design theme for Hexo", "main": "package.json", "scripts": { diff --git a/plugins.yml b/plugins.yml index dd0e9d7..c79ad44 100644 --- a/plugins.yml +++ b/plugins.yml @@ -9,7 +9,7 @@ activate_power_mode: algolia_search: name: algoliasearch file: dist/lite/builds/browser.umd.js - version: 5.20.2 + version: 5.20.3 aplayer_css: name: aplayer file: dist/APlayer.min.css @@ -45,7 +45,7 @@ canvas_ribbon: chartjs: name: chart.js file: dist/chart.umd.js - version: 4.4.7 + version: 4.4.8 clickShowText: name: butterfly-extsrc file: dist/click-show-text.min.js @@ -66,12 +66,12 @@ docsearch_css: name: '@docsearch/css' other_name: docsearch-css file: dist/style.css - version: 3.8.3 + version: 3.9.0 docsearch_js: name: '@docsearch/js' other_name: docsearch-js file: dist/umd/index.js - version: 3.8.3 + version: 3.9.0 egjs_infinitegrid: name: '@egjs/infinitegrid' other_name: egjs-infinitegrid @@ -203,9 +203,9 @@ waline_css: name: '@waline/client' file: dist/waline.css other_name: waline - version: 3.5.2 + version: 3.5.5 waline_js: name: '@waline/client' file: dist/waline.js other_name: waline - version: 3.5.2 + version: 3.5.5 diff --git a/scripts/helpers/inject_head_js.js b/scripts/helpers/inject_head_js.js index 5598674..16e9b9a 100644 --- a/scripts/helpers/inject_head_js.js +++ b/scripts/helpers/inject_head_js.js @@ -89,7 +89,7 @@ hexo.extend.helper.register('inject_head_js', function () { darkmodeJs += ` const mediaQueryDark = window.matchMedia('(prefers-color-scheme: dark)') const mediaQueryLight = window.matchMedia('(prefers-color-scheme: light)') - + if (theme === undefined) { if (mediaQueryLight.matches) activateLightMode() else if (mediaQueryDark.matches) activateDarkMode() diff --git a/source/css/_global/index.styl b/source/css/_global/index.styl index 0ddabb0..212f654 100644 --- a/source/css/_global/index.styl +++ b/source/css/_global/index.styl @@ -10,8 +10,8 @@ --preloader-bg: $preloader-bg --preloader-color: $preloader-word-color --tab-border-color: $tab-border-color - --tab-botton-bg: $tab-botton-bg - --tab-botton-color: $tab-botton-color + --tab-button-bg: $tab-button-bg + --tab-button-color: $tab-button-color --tab-button-hover-bg: $tab-button-hover-bg --tab-button-active-bg: $tab-button-active-bg --card-bg: $card-bg diff --git a/source/css/_mode/darkmode.styl b/source/css/_mode/darkmode.styl index ef397cc..bcd5334 100644 --- a/source/css/_mode/darkmode.styl +++ b/source/css/_mode/darkmode.styl @@ -10,8 +10,8 @@ if hexo-config('darkmode.enable') || hexo-config('display_mode') == 'dark' --preloader-bg: darken(#121212, 2) --preloader-color: alpha(#FFFFFF, .7) --tab-border-color: #2c2c2c - --tab-botton-bg: #2c2c2c - --tab-botton-color: alpha(#FFFFFF, .7) + --tab-button-bg: #2c2c2c + --tab-button-color: alpha(#FFFFFF, .7) --tab-button-hover-bg: lighten(#121212, 15) --tab-button-active-bg: #121212 --card-bg: #121212 diff --git a/source/css/_tags/tabs.styl b/source/css/_tags/tabs.styl index d57ba59..2eba12d 100644 --- a/source/css/_tags/tabs.styl +++ b/source/css/_tags/tabs.styl @@ -14,14 +14,14 @@ flex-wrap: wrap margin: 0 padding: 0 - background: var(--tab-botton-bg) + background: var(--tab-button-bg) > .tab flex-grow: 1 padding: 8px 18px border-top: 2px solid var(--tab-border-color) - background: var(--tab-botton-bg) - color: var(--tab-botton-color) + background: var(--tab-button-bg) + color: var(--tab-button-color) line-height: 2 transition: all .4s diff --git a/source/css/var.styl b/source/css/var.styl index 479c3b7..fd6ead8 100644 --- a/source/css/var.styl +++ b/source/css/var.styl @@ -14,18 +14,18 @@ $code-background = $themeColorEnable && hexo-config('theme_color.code_background $theme-toc-color = $themeColorEnable && hexo-config('theme_color.toc_color') ? convert(hexo-config('theme_color.toc_color')) : $strong-cyan // font -$chinseFont = $language == 'zh-CN' ? 'Microsoft YaHei' : 'Microsoft JhengHei' -$dafault-font-family = -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Lato, Roboto, 'PingFang SC', $chinseFont, sans-serif -$dafault-code-font = consolas, Menlo, monospace, 'PingFang SC', $chinseFont, sans-serif +$chineseFont = $language == 'zh-CN' ? 'Microsoft YaHei' : 'Microsoft JhengHei' +$default-font-family = -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Lato, Roboto, 'PingFang SC', $chineseFont, sans-serif +$default-code-font = consolas, Menlo, monospace, 'PingFang SC', $chineseFont, sans-serif -$font-family = hexo-config('font.font_family') ? unquote(hexo-config('font.font_family')) : $dafault-font-family -$code-font-family = hexo-config('font.code_font_family') ? unquote(hexo-config('font.code_font_family')) : $dafault-code-font +$font-family = hexo-config('font.font_family') ? unquote(hexo-config('font.font_family')) : $default-font-family +$code-font-family = hexo-config('font.code_font_family') ? unquote(hexo-config('font.code_font_family')) : $default-code-font $site-name-font = hexo-config('blog_title_font.font_family') && unquote(hexo-config('blog_title_font.font_family')) // hr $hrEnable = hexo-config('hr_icon') && hexo-config('hr_icon.enable') $hr-icon = $hrEnable && hexo-config('hr_icon.icon') ? hexo-config('hr_icon.icon') : '\f0c4' $hr-icon-top = $hrEnable && hexo-config('hr_icon.icon_top') ? convert(hexo-config('hr_icon.icon_top')) : -10px -// page beatutify +// page beautify $beautifyEnable = hexo-config('beautify.enable') $title-prefix-icon = $beautifyEnable && hexo-config('beautify.title_prefix_icon') ? hexo-config('beautify.title_prefix_icon') : '\f0c1' $title-prefix-icon-color = $beautifyEnable && hexo-config('beautify.title_prefix_icon_color') ? convert(hexo-config('beautify.title_prefix_icon_color')) : $light-red @@ -175,8 +175,8 @@ $tagsP-purple-color = #6f42c1 $tagsP-green-color = #5cb85c // Tag Plugins - Tab $tab-border-color = #f0f0f0 -$tab-botton-bg = #f0f0f0 -$tab-botton-color = $font-color +$tab-button-bg = #f0f0f0 +$tab-button-color = $font-color $tab-button-hover-bg = darken($tab-border-color, 8) $tab-active-border-color = $theme-color $tab-button-active-bg = $card-bg