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/3] 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/3] 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 `
${escapeHtmlTags(content)}
`
+
+ const trimmed = content.trim()
+ // 使用六个横线作为分隔符拆分内容
+ const parts = trimmed.split('------')
+
+ if (parts.length < 2) {
+ // 如果没有分隔符,直接将整个内容作为乐谱内容处理
+ return `${escapeHtmlTags(trimmed)}
`
+ }
+
+ // 第一部分为参数(JSON 字符串),其余部分作为乐谱内容
+ const paramPart = parts[0].trim()
+ const scorePart = parts.slice(1).join('------').trim()
+
+ let paramsObj = {}
+ try {
+ paramsObj = JSON.parse(paramPart)
+ } catch (e) {
+ console.error('解析 score 标签中的参数 JSON 失败:', e)
+ }
+
+ // 使用双引号包裹 data-params 的属性值,确保 JSON 内部的双引号已被转义
+ return `
+ ${escapeHtmlTags(scorePart)}
+
`
}
hexo.extend.tag.register('score', score, { ends: true })
+
From 576fa5c80e7b7e641e83602d998179eaaca6bdfb Mon Sep 17 00:00:00 2001
From: Yuchen Mu <2012026@mail.nankai.edu.cn>
Date: Sun, 2 Mar 2025 10:23:40 +0800
Subject: [PATCH 3/3] fix: resolve issues from previous commit about feat(score
tag)
---
layout/includes/third-party/abcjs/abcjs.pug | 63 ++++++++++-----------
scripts/tag/score.js | 28 ++++-----
2 files changed, 43 insertions(+), 48 deletions(-)
diff --git a/layout/includes/third-party/abcjs/abcjs.pug b/layout/includes/third-party/abcjs/abcjs.pug
index 45d6924..9de2b97 100644
--- a/layout/includes/third-party/abcjs/abcjs.pug
+++ b/layout/includes/third-party/abcjs/abcjs.pug
@@ -1,51 +1,46 @@
script.
(function() {
- var abcjsInit = function() {
- var abcjsFn = function() {
+ const abcjsInit = function() {
+ const 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");
+ const sheets = document.querySelectorAll(".abc-music-sheet")
+ for (let i = 0; i < sheets.length; i++) {
+ const ele = sheets[i]
+ if (ele.children.length > 0) continue
+
+ // Parse parameters from data-params attribute
+ let params = {}
+ const dp = ele.getAttribute("data-params")
if (dp) {
try {
- params = JSON.parse(dp);
+ params = JSON.parse(dp)
} catch (e) {
- console.error("解析 data-params 失败:", e);
+ console.error("Failed to parse 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);
+
+ // Merge parsed parameters with the responsive option
+ // Ensures params content appears before responsive
+ const options = { ...params, responsive: "resize" }
+
+ // Render the music score using ABCJS.renderAbc
+ ABCJS.renderAbc(ele, ele.innerHTML, options)
}
- }, 100);
- };
+ }, 100)
+ }
if (typeof ABCJS === "object") {
- abcjsFn();
+ abcjsFn()
} else {
- btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn);
+ btf.getScript("!{url_for(theme.asset.abcjs_basic_js)}").then(abcjsFn)
}
- };
+ }
if (window.pjax) {
- abcjsInit();
+ abcjsInit()
} else {
- window.addEventListener("load", abcjsInit);
+ window.addEventListener("load", abcjsInit)
}
- btf.addGlobalFn("encrypt", abcjsInit, "abcjs");
- })();
\ No newline at end of file
+
+ btf.addGlobalFn("encrypt", abcjsInit, "abcjs")
+ })()
diff --git a/scripts/tag/score.js b/scripts/tag/score.js
index f4add38..df345e5 100644
--- a/scripts/tag/score.js
+++ b/scripts/tag/score.js
@@ -6,12 +6,12 @@
'use strict'
const score = (args, content) => {
- // 转义 HTML 标签和部分特殊字符,包括花括号
+ // Escape HTML tags and some special characters, including curly braces
const escapeHtmlTags = s => {
const lookup = {
'&': '&',
'"': '"',
- '\'': ''',
+ "'": ''',
'<': '<',
'>': '>',
'{': '{',
@@ -19,32 +19,32 @@ const score = (args, content) => {
}
return s.replace(/[&"'<>{}]/g, c => lookup[c])
}
-
+
const trimmed = content.trim()
- // 使用六个横线作为分隔符拆分内容
+ // Split content using six dashes as a delimiter
const parts = trimmed.split('------')
-
+
if (parts.length < 2) {
- // 如果没有分隔符,直接将整个内容作为乐谱内容处理
+ // If no delimiter is found, treat the entire content as the score
return `${escapeHtmlTags(trimmed)}
`
}
-
- // 第一部分为参数(JSON 字符串),其余部分作为乐谱内容
+
+ // First part is parameters (JSON string), the rest is the score content
const paramPart = parts[0].trim()
const scorePart = parts.slice(1).join('------').trim()
-
+
let paramsObj = {}
try {
paramsObj = JSON.parse(paramPart)
} catch (e) {
- console.error('解析 score 标签中的参数 JSON 失败:', e)
+ console.error("Failed to parse JSON in score tag:", e)
}
-
- // 使用双引号包裹 data-params 的属性值,确保 JSON 内部的双引号已被转义
+
+ // Use double quotes for data-params attribute value,
+ // ensuring JSON internal double quotes are escaped
return `
${escapeHtmlTags(scorePart)}
`
}
-hexo.extend.tag.register('score', score, { ends: true })
-
+hexo.extend.tag.register("score", score, { ends: true })
\ No newline at end of file