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:
Cell
2025-10-21 15:47:04 +08:00
committed by GitHub
parent 6907fd03dc
commit fe129dd207
11 changed files with 128 additions and 7 deletions
+23
View File
@@ -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 -}}
+40
View File
@@ -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 -}}
+1 -1
View File
@@ -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" -}}