From b34eeb042518701d9bc7c081f68c887a632a72aa Mon Sep 17 00:00:00 2001 From: LittleNyima Date: Tue, 28 Mar 2023 14:14:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81abcjs=E4=B9=90?= =?UTF-8?q?=E8=B0=B1=E6=B8=B2=E6=9F=93=20=20-=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=8F=AF=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9?= =?UTF-8?q?=20=20-=20=E6=B7=BB=E5=8A=A0=E6=B8=B2=E6=9F=93=E4=B8=8E?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=B3=A8=E5=86=8C=E7=9B=B8=E5=85=B3=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=20=20-=20=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4cdn?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 7 +++++++ layout/includes/additional-js.pug | 9 +++++++++ layout/includes/third-party/abcjs.pug | 18 ++++++++++++++++++ plugins.yml | 5 +++++ scripts/tag/score.js | 22 ++++++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 layout/includes/third-party/abcjs.pug create mode 100644 scripts/tag/score.js diff --git a/_config.yml b/_config.yml index db17670..2a59a95 100644 --- a/_config.yml +++ b/_config.yml @@ -862,6 +862,13 @@ lazyload: # favicon_16_16: /pwa/16.png # mask_icon: /pwa/safari-pinned-tab.svg +# abcjs (樂譜渲染) +# See https://github.com/paulrosen/abcjs +# --------------- +abcjs: + enable: false + per_page: false + # Open graph meta tags # https://developers.facebook.com/docs/sharing/webmasters/ Open_Graph_meta: diff --git a/layout/includes/additional-js.pug b/layout/includes/additional-js.pug index 3cb29f4..60646ae 100644 --- a/layout/includes/additional-js.pug +++ b/layout/includes/additional-js.pug @@ -59,3 +59,12 @@ div if theme.busuanzi.site_uv || theme.busuanzi.site_pv || theme.busuanzi.page_pv script(async data-pjax src= theme.asset.busuanzi || '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js') + + if theme.abcjs.enable + if theme.abcjs.per_page + if is_post() || is_page() + script(src=url_for(theme.asset.abcjs_basic_js)) + include ./third-party/abcjs.pug + else if page.abcjs + script(src=url_for(theme.asset.abcjs_basic_js)) + include ./third-party/abcjs.pug diff --git a/layout/includes/third-party/abcjs.pug b/layout/includes/third-party/abcjs.pug new file mode 100644 index 0000000..c8a1c06 --- /dev/null +++ b/layout/includes/third-party/abcjs.pug @@ -0,0 +1,18 @@ +script. + function abcjsInit() { + function abcjsFn() { + for (let abcContainer of document.getElementsByClassName("abc-music-sheet")) { + ABCJS.renderAbc(abcContainer, abcContainer.innerHTML, {responsive: 'resize'}); + } + } + if (typeof ABCJS === 'object') { + abcjsFn(); + } else { + getScript('!{url_for(theme.asset.abcjs_basic_js)}') + .then(() => { + abcjsFn(); + }); + } + } + + document.addEventListener('DOMContentLoaded', abcjsInit); \ No newline at end of file diff --git a/plugins.yml b/plugins.yml index b672299..2e25388 100644 --- a/plugins.yml +++ b/plugins.yml @@ -208,3 +208,8 @@ docsearch_css: other_name: docsearch-css file: dist/style.css version: 3.3.3 +abcjs_basic_js: + name: abcjs + other_name: abcjs-basic + file: dist/abcjs-basic-min.js + version: 6.1.9 \ No newline at end of file diff --git a/scripts/tag/score.js b/scripts/tag/score.js new file mode 100644 index 0000000..3157245 --- /dev/null +++ b/scripts/tag/score.js @@ -0,0 +1,22 @@ +/** + * Music Score + * {% score %} + */ + +'use strict'; + +function score(args, content) { + function escapeHtmlTags(s) { + let lookup = { + '&': "&", + '"': """, + '\'': "'", + '<': "<", + '>': ">" + }; + return s.replace(/[&"'<>]/g, c => lookup[c]); + } + return `
${escapeHtmlTags(content)}
`; +} + +hexo.extend.tag.register('score', score, {ends: true});