mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
feat: add APlayer shortcode and audio support (#650)
* docs: improve error message clarity for shortcode parent block validation * feat: add APlayer shortcode and audio support * feat: support both APlayer and MetingJS * feat: initialize APlayer when content decrypted
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
---
|
||||
title: "Alerts and Admonition Syntax Test"
|
||||
title: Alerts and Admonition Syntax Test
|
||||
date: 2025-09-05T16:57:58+08:00
|
||||
draft: false
|
||||
collections:
|
||||
- Tests
|
||||
categories:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[00:00.00]APlayer audio1
|
||||
[00:04.01]is
|
||||
[00:08.02]amazing
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
@@ -0,0 +1,26 @@
|
||||
---
|
||||
title: APlayer Test
|
||||
date: 2025-10-21T11:00:04+08:00
|
||||
collections:
|
||||
- Tests
|
||||
categories:
|
||||
- Shortcodes
|
||||
tags:
|
||||
- APlayer
|
||||
---
|
||||
|
||||
<!--more-->
|
||||
|
||||
{{< aplayer fixed=false mini=false autoplay=false theme="#b7daff" loop="all" order="list" preload="auto" volume=0.7 mutex=true lrcType=3 listFolded=false listMaxHeight="" storageName="aplayer-setting" >}}
|
||||
{{< audio name="Wavelength1" artist="oldmanyoung1" url="Wavelength.mp3" cover="Wavelength.webp" lrc="Wavelength.lrc" />}}
|
||||
{{< audio name="Wavelength2" artist="oldmanyoung2" url="Wavelength.mp3" cover="Wavelength.webp" />}}
|
||||
{{< /aplayer >}}
|
||||
|
||||
{{< aplayer fixed=false mini=false autoplay=false theme="#b7daff" loop="all" order="list" preload="auto" volume=0.7 mutex=true lrcType=1 listFolded=false listMaxHeight="" storageName="aplayer-setting" >}}
|
||||
{{< audio name="Wavelength1" artist="oldmanyoung1" url="Wavelength.mp3" cover="Wavelength.webp" />}}
|
||||
{{< audio name="Wavelength2" artist="oldmanyoung2" url="Wavelength.mp3" cover="Wavelength.webp" >}}
|
||||
[00:00.00]APlayer audio2
|
||||
[00:04.01]is
|
||||
[00:08.02]amazing
|
||||
{{< /audio >}}
|
||||
{{< /aplayer >}}
|
||||
@@ -0,0 +1,19 @@
|
||||
window.FixItAPlayer = {
|
||||
init: () => {
|
||||
Array.from(document.getElementsByClassName("aplayer-shortcode")).forEach((aplayer) => {
|
||||
if (aplayer.dataset.processed) return
|
||||
const audio = JSON.parse(aplayer.dataset.audio)
|
||||
const options = JSON.parse(aplayer.dataset.options)
|
||||
options.audio = audio
|
||||
options.container = aplayer
|
||||
new APlayer(options)
|
||||
aplayer.dataset.processed = true
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
if (document.readyState !== 'loading') {
|
||||
window.FixItAPlayer.init()
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', window.FixItAPlayer.init, false)
|
||||
}
|
||||
@@ -1118,6 +1118,7 @@ class FixIt {
|
||||
this.initMathJax();
|
||||
this.initJsonViewer();
|
||||
window.FixItMermaid?.init?.();
|
||||
window.FixItAPlayer?.init?.();
|
||||
this.util.forEach(document.querySelectorAll('.encrypted-hidden'), ($element) => {
|
||||
$element.classList.replace('encrypted-hidden', 'decrypted-shown');
|
||||
});
|
||||
@@ -1136,6 +1137,7 @@ class FixIt {
|
||||
this.initMathJax();
|
||||
this.initJsonViewer();
|
||||
window.FixItMermaid?.init?.();
|
||||
window.FixItAPlayer?.init?.();
|
||||
this.util.forEach($content.querySelectorAll('.encrypted-hidden'), ($element) => {
|
||||
$element.classList.replace('encrypted-hidden', 'decrypted-shown');
|
||||
});
|
||||
|
||||
@@ -173,7 +173,7 @@ FixIt theme assets partial
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Music */ -}}
|
||||
{{- if .HasShortcode "music" -}}
|
||||
{{- if (.HasShortcode "aplayer") | or (.HasShortcode "music") -}}
|
||||
{{- /* APlayer */ -}}
|
||||
{{- $source := $cdn.aplayerCSS | default "lib/aplayer/APlayer.min.css" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Preload" true | dict "Page" . "Data" | partial "store/style.html" -}}
|
||||
@@ -182,9 +182,18 @@ FixIt theme assets partial
|
||||
{{- $source := $cdn.aplayerJS | default "lib/aplayer/APlayer.min.js" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
|
||||
{{- /* MetingJS */ -}}
|
||||
{{- $source := $cdn.metingJS | default "lib/meting/Meting.min.js" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
{{- if .HasShortcode "aplayer" -}}
|
||||
{{- $options := dict "targetPath" "js/lib/aplayer.min.js" "minify" hugo.IsProduction -}}
|
||||
{{- if not hugo.IsProduction -}}
|
||||
{{- $options = dict "sourceMap" "external" | merge $options -}}
|
||||
{{- end -}}
|
||||
{{- dict "Source" (resources.Get "js/lib/aplayer.js") "Build" $options "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
{{- end -}}
|
||||
{{- if .HasShortcode "music" -}}
|
||||
{{- /* MetingJS */ -}}
|
||||
{{- $source := $cdn.metingJS | default "lib/meting/Meting.min.js" -}}
|
||||
{{- dict "Source" $source "Fingerprint" $fingerprint "Defer" true | dict "Page" . "Data" | partial "store/script.html" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Tabs and tab */ -}}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{{- if .IsNamedParams -}}
|
||||
{{- $options := dict -}}
|
||||
{{- with .Get "fixed" -}}{{- $options = dict "fixed" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "mini" -}}{{- $options = dict "mini" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "autoplay" -}}{{- $options = dict "autoplay" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "theme" -}}{{- $options = dict "theme" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "loop" -}}{{- $options = dict "loop" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "order" -}}{{- $options = dict "order" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "preload" -}}{{- $options = dict "preload" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "volume" -}}{{- $options = dict "volume" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "mutex" -}}{{- $options = dict "mutex" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "lrcType" -}}{{- $options = dict "lrcType" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "listFolded" -}}{{- $options = dict "listFolded" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "listMaxHeight" -}}{{- $options = dict "listMaxHeight" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "storageName" -}}{{- $options = dict "storageName" . | merge $options -}}{{- end -}}
|
||||
{{- $options = $options | jsonify -}}
|
||||
{{- $audio := trim .Inner " \r\n" -}}
|
||||
{{- $audio = replace $audio "}" "}," | printf "[%s]" -}}
|
||||
{{- $audio = replace $audio ",]" "]" -}}
|
||||
<div class="aplayer-shortcode" data-audio="{{ $audio }}" data-options="{{ $options }}"></div>
|
||||
{{- else -}}
|
||||
{{- errorf "Only named params is supported: %s" .Position -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,40 @@
|
||||
{{- with $.Parent -}}
|
||||
{{- if ne $.Parent.Name "aplayer" -}}
|
||||
{{- errorf "Found shortcode %q enclosed inside a %q block, must be enclosed inside a %q block. Error position: %s" $.Name $.Parent.Name "aplayer" $.Position -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- errorf "The shortcode %q must be enclosed inside a %q block, but no parent block was found. Error position: %s" $.Name "aplayer" $.Position -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .IsNamedParams -}}
|
||||
{{- $options := dict -}}
|
||||
{{- with .Get "name" -}}{{- $options = dict "name" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "artist" -}}{{- $options = dict "artist" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "url" -}}
|
||||
{{- $url := . -}}
|
||||
{{- with dict "Path" $url | partial "function/resource.html" -}}
|
||||
{{- $url = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- $options = dict "url" $url | merge $options -}}
|
||||
{{- end -}}
|
||||
{{- with .Get "cover" -}}
|
||||
{{- $cover := . -}}
|
||||
{{- with dict "Path" $cover | partial "function/resource.html" -}}
|
||||
{{- $cover = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- $options = dict "cover" $cover | merge $options -}}
|
||||
{{- end -}}
|
||||
{{- with .Get "lrc" -}}
|
||||
{{- $lrc := . -}}
|
||||
{{- with dict "Path" $lrc | partial "function/resource.html" -}}
|
||||
{{- $lrc = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- $options = dict "lrc" $lrc | merge $options -}}
|
||||
{{- end -}}
|
||||
{{- with .Inner -}}{{- $options = dict "lrc" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "theme" -}}{{- $options = dict "theme" . | merge $options -}}{{- end -}}
|
||||
{{- with .Get "type" -}}{{- $options = dict "type" . | merge $options -}}{{- end -}}
|
||||
{{- $options | jsonify -}}
|
||||
{{- else -}}
|
||||
{{- errorf "Only named params is supported: %s" .Position -}}
|
||||
{{- end -}}
|
||||
@@ -3,7 +3,7 @@
|
||||
{{- errorf "Found shortcode %q enclosed inside a %q block, must be enclosed inside a %q block. Error position: %s" $.Name $.Parent.Name "tabs" $.Position -}}
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- errorf "shortcode %q must be enclosed inside a %q block, but no parent block was found. Error position: %s" $.Name "tabs" $.Position -}}
|
||||
{{- errorf "The shortcode %q must be enclosed inside a %q block, but no parent block was found. Error position: %s" $.Name "tabs" $.Position -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $id := dict "Page" .Page | partial "function/id.html" -}}
|
||||
|
||||
Reference in New Issue
Block a user