mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2025-09-15 12:58:48 +08:00
feat: 支持abcjs乐谱渲染
- 添加相关可配置选项 - 添加渲染与组件注册相关脚本 - 添加默认cdn配置
This commit is contained in:
parent
63dc605794
commit
b34eeb0425
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
18
layout/includes/third-party/abcjs.pug
vendored
Normal file
18
layout/includes/third-party/abcjs.pug
vendored
Normal file
@ -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);
|
||||
@ -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
|
||||
22
scripts/tag/score.js
Normal file
22
scripts/tag/score.js
Normal file
@ -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 `<div class="abc-music-sheet">${escapeHtmlTags(content)}</div>`;
|
||||
}
|
||||
|
||||
hexo.extend.tag.register('score', score, {ends: true});
|
||||
Loading…
Reference in New Issue
Block a user