Merge pull request #1239 from LittleNyima/patch-abcjs

feat: 支持abcjs乐谱渲染
This commit is contained in:
Jerry Wong
2023-04-03 18:53:53 +08:00
committed by GitHub
Unverified
7 changed files with 66 additions and 1 deletions
+8
View File
@@ -787,6 +787,13 @@ fancybox: true
# Tag Plugins settings (標籤外掛) # Tag Plugins settings (標籤外掛)
# -------------------------------------- # --------------------------------------
# abcjs (樂譜渲染)
# See https://github.com/paulrosen/abcjs
# ---------------
abcjs:
enable: false
per_page: true
# mermaid # mermaid
# see https://github.com/mermaid-js/mermaid # see https://github.com/mermaid-js/mermaid
mermaid: mermaid:
@@ -967,3 +974,4 @@ CDN:
# artalk_js: # artalk_js:
# artalk_css: # artalk_css:
# busuanzi: # busuanzi:
# abcjs_basic_js:
+2
View File
@@ -31,6 +31,8 @@ div
include ./third-party/math/index.pug include ./third-party/math/index.pug
include ./third-party/abcjs/index.pug
if commentsJsLoad if commentsJsLoad
include ./third-party/comments/js.pug include ./third-party/comments/js.pug
+15
View File
@@ -0,0 +1,15 @@
script.
(() => {
function abcjsInit() {
function abcjsFn() {
for (let abcContainer of document.getElementsByClassName("abc-music-sheet")) {
ABCJS.renderAbc(abcContainer, abcContainer.innerHTML, {responsive: 'resize'})
}
}
typeof ABCJS === 'object' ? abcjsFn()
: getScript('!{url_for(theme.asset.abcjs_basic_js)}').then(abcjsFn)
}
window.pjax ? abcjsInit() : document.addEventListener('DOMContentLoaded', abcjsInit)
})()
+6
View File
@@ -0,0 +1,6 @@
if theme.abcjs.enable
if theme.abcjs.per_page
if is_post() || is_page()
include ./abcjs.pug
else if page.abcjs
include ./abcjs.pug
+4
View File
@@ -208,3 +208,7 @@ docsearch_css:
other_name: docsearch-css other_name: docsearch-css
file: dist/style.css file: dist/style.css
version: 3.3.3 version: 3.3.3
abcjs_basic_js:
name: abcjs
file: dist/abcjs-basic-min.js
version: 6.1.9
+22
View File
@@ -0,0 +1,22 @@
/**
* Music Score
* {% score %}
*/
'use strict';
function score(args, content) {
function escapeHtmlTags(s) {
let lookup = {
'&': "&",
'"': """,
'\'': "'",
'<': "&lt;",
'>': "&gt;"
};
return s.replace(/[&"'<>]/g, c => lookup[c]);
}
return `<div class="abc-music-sheet">${escapeHtmlTags(content)}</div>`;
}
hexo.extend.tag.register('score', score, {ends: true});
+9 -1
View File
@@ -115,6 +115,14 @@ span.mathjax-overflow
.snackbar-css .snackbar-css
border-radius: 5px !important border-radius: 5px !important
.abc-music-sheet
margin: 0 0 20px
opacity: 0
transition: opacity .3s
&.abcjs-container
opacity: 1
+maxWidth768() +maxWidth768()
.fancybox__toolbar__column.is-middle .fancybox__toolbar__column.is-middle
display: none display: none