Use store method impl the music etc shortcode.

This commit is contained in:
elkan1788 2025-01-15 21:42:22 +08:00
parent 088da43913
commit b2e0be5a6a
16 changed files with 70 additions and 32 deletions

View File

@ -9,10 +9,10 @@ HTMLElement.prototype.wrap = function (wrapper) {
NexT.utils = { NexT.utils = {
registerAPlayer: function () { registerAPlayer: function () {
this.getStyle( this.getStyle(
NexT.utils.getCDNResource(NexT.CONFIG.page.aplayer.css) NexT.utils.getCDNResource(NexT.CONFIG.page.music.css)
); );
NexT.CONFIG.page.aplayer.js.forEach(function (js) { NexT.CONFIG.page.music.js.forEach(function (js) {
NexT.utils.getScript(NexT.utils.getCDNResource(js), true); NexT.utils.getScript(NexT.utils.getCDNResource(js), true);
}); });

View File

@ -14,7 +14,6 @@ tags:
- 时序图 - 时序图
url: "demo/mermaid-charts.html" url: "demo/mermaid-charts.html"
mermaid: true
toc: true toc: true
--- ---
@ -28,7 +27,6 @@ toc: true
{{< note info >}} {{< note info >}}
- 通过 `hugo new` 命令创建一篇新的文章 - 通过 `hugo new` 命令创建一篇新的文章
- 在文章头部配置 `mermaid: true`
- 使用短代码书写各种类型的图自带2个参数 align对齐 和 bc背景色可参考如下使用示例 - 使用短代码书写各种类型的图自带2个参数 align对齐 和 bc背景色可参考如下使用示例
{{< /note >}} {{< /note >}}

View File

@ -14,7 +14,6 @@ tags:
- 语法 - 语法
url: "demo/shortcodes.html" url: "demo/shortcodes.html"
toc: true toc: true
music: true
--- ---
虽然 `Markdown` 语法已经非常丰富能够满足我们写文章的绝大部分需求,但是为更好的对文章内容进行更友好的排版,为引设计一套自定义的短语,便于在使用时能够快速引用。 虽然 `Markdown` 语法已经非常丰富能够满足我们写文章的绝大部分需求,但是为更好的对文章内容进行更友好的排版,为引设计一套自定义的短语,便于在使用时能够快速引用。
@ -101,7 +100,7 @@ music: true
或者 或者
{{</* bilibili id=BV1Sx411T7QQ */>}} {{</* bilibili id=BV1Sx411T7QQ */>}}
``` ```
{{</** bilibili id=BV1Sx411T7QQ **/>}} {{< bilibili id=BV1Sx411T7QQ >}}
## 音乐播放器 ## 音乐播放器
@ -131,23 +130,22 @@ music: true
### 单曲播放 ### 单曲播放
```markdown ```markdown
{{</* music theme="#2980b9" server="netease" type="song" id="1868553" mini="true" */>}} {{</* music theme="#2980b9" server="tencent" type="song" id="002u4ZTb0CXmJA" mini="true" */>}}
``` ```
{{< music theme="#2980b9" server="netease" type="song" id="1868553" mini="true" >}} {{< music theme="#2980b9" server="tencent" type="song" id="002u4ZTb0CXmJA" mini="true" >}}
### 列表播放 ### 列表播放
```markdown ```markdown
{{</* music server="netease" type="playlist" id="769332917" list-max-height="140" */>}} {{</* music server="netease" type="playlist" id="1982066521" list-max-height="140" */>}}
``` ```
{{< music server="netease" type="playlist" id="769332917" list-max-height="140px" >}} {{< music server="netease" type="playlist" id="1982066521" list-max-height="140px" >}}
### 自定义音乐源 ### 自定义音乐源
```markdown ```markdown
{{</* music url="https://ri-sycdn.kuwo.cn/ea345253b94e7ad564e6fb0cdf37fee6/677b6574/resource/n1/87/56/4272600974.mp3" name="天空之城" artist="宫崎骏" cover="http://img4.kuwo.cn/star/starheads/500/27/66/2532818318.jpg" autoplay="true" */>}} {{</* music music url="/music/sky.mp3" name="天空之城" artist="宫崎骏" cover="/music/gongqijun.jpg" autoplay="true" */>}}
``` ```
{{< music url="https://ri-sycdn.kuwo.cn/ea345253b94e7ad564e6fb0cdf37fee6/677b6574/resource/n1/87/56/4272600974.mp3" name="天空之城" artist="宫崎骏" cover="http://img4.kuwo.cn/star/starheads/500/27/66/2532818318.jpg" autoplay="true" >}} {{< music url="/music/sky.mp3" name="天空之城" artist="宫崎骏" cover="/music/gongqijun.jpg" autoplay="true" >}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

View File

@ -4,7 +4,7 @@
{{ partial "head/googleplus.html" . }} {{ partial "head/googleplus.html" . }}
{{ partial "head/facebook.html" . }} {{ partial "head/facebook.html" . }}
{{ partial "head/verify.html" . }} {{ partial "head/verify.html" . }}
{{ partialCached "head/style.html" . }} {{ partial "head/styles.html" . }}
<script type="text/javascript"> <script type="text/javascript">
(function(){ (function(){
localDB = { localDB = {
@ -61,5 +61,5 @@
})(window); })(window);
</script> </script>
{{ partial "head/config.html" . }} {{ partial "head/config.html" . }}
{{ partialCached "head/analytics.html" . }} {{ partialCached "head/script/analytics.html" . }}

View File

@ -1,21 +1,24 @@
{{/** Short code params **/}}
{{ $scParam := .Store.Get "scParams" }}
{{ $pageCfg := dict {{ $pageCfg := dict
"isHome" .IsHome "isHome" .IsHome
"isPage" .IsPage "isPage" .IsPage
"comments" (.Scratch.Get "isComment") "comments" (.Scratch.Get "isComment")
"toc" (default .Site.Params.toc.enable .Params.Toc) "toc" (default .Site.Params.toc.enable .Params.Toc)
"music" .Params.music
"permalink" (.Page.Permalink | absURL) "permalink" (.Page.Permalink | absURL)
"path" (.Page.Permalink | path.Base) "path" (.Page.Permalink | path.Base)
"title" .Page.Title "title" .Page.Title
}} }}
{{/** Append APlayer plugin */}} {{/** Append APlayer plugin */}}
{{ if .Params.music }} {{ if $scParam.music }}
{{ $aplayer := dict {{ $aplayer := dict
"js" $.Site.Data.resources.plugins.music.js "js" $.Site.Data.resources.plugins.music.js
"css" $.Site.Data.resources.plugins.music.css "css" $.Site.Data.resources.plugins.music.css
}} }}
{{ $pageCfg = merge $pageCfg (dict "aplayer" $aplayer) }} {{ $pageCfg = merge $pageCfg (dict "music" $aplayer) }}
{{ end }} {{ end }}
{{/* Append post expired config */}} {{/* Append post expired config */}}
@ -51,7 +54,7 @@
{{ end }} {{ end }}
{{/* Append mermaid plugin */}} {{/* Append mermaid plugin */}}
{{ if .Params.mermaid }} {{ if $scParam.mermaid }}
{{ $mermaid := dict {{ $mermaid := dict
"js" .Site.Data.resources.plugins.mermaid.js "js" .Site.Data.resources.plugins.mermaid.js
}} }}
@ -73,3 +76,14 @@
{{ end }} {{ end }}
<script class="next-config" data-name="page" type="application/json">{{ $pageCfg }}</script> <script class="next-config" data-name="page" type="application/json">{{ $pageCfg }}</script>
{{/** Special CSS Style for page **/}}
{{ if .IsPage }}
<style type="text/css">
.post-footer, .flinks-list-footer hr:after {
content: "{{ .Site.Params.postFooter.endLineTip }}";
}
</style>
{{ end }}

View File

@ -1,9 +1,17 @@
{{/* Defind loading plugin scripts which only need in pages */}} {{/* Defind loading plugin scripts which only need in pages */}}
{{ if .IsPage }}
{{/** Short code params **/}}
{{ $scParam := .Store.Get "scParams" }}
{{/** Append math render action **/}}
{{ if or .Params.math .Site.Params.math }} {{ if or .Params.math .Site.Params.math }}
{{ partial "_funs/get_plugin.html" (dict "ctx" . "class" "others" "plugin" "math.js") }} {{ partial "_funs/get_plugin.html" (dict "ctx" . "class" "others" "plugin" "math.js") }}
{{ end }} {{ end }}
{{ if .Params.mermaid }} {{/** Append mermaid render action **/}}
{{ if $scParam.mermaid }}
{{ partial "_funs/get_plugin.html" (dict "ctx" . "class" "others" "plugin" "mermaid.js") }} {{ partial "_funs/get_plugin.html" (dict "ctx" . "class" "others" "plugin" "mermaid.js") }}
{{ end }} {{ end }}
{{ end }}

View File

@ -0,0 +1,3 @@
.post-footer, .flinks-list-footer hr:after {
content: "{{ .Site.Params.postFooter.endLineTip }}";
}

View File

@ -0,0 +1,13 @@
{{/* Defind loading plugin entend style which only need in pages */}}
{{ if .IsPage }}
{{/** Short code params **/}}
{{ $scParam := .Store.Get "scParams" }}
{{ if $scParam.mermaid }}
.post-block .post-body .mermaid {
background: var(--highlight-foreground);
}
{{ end }}
{{ end }}

View File

@ -17,14 +17,14 @@
{{ end }} {{ end }}
{{ $unixHref := partial "_funs/add_unix_param.html" $css.RelPermalink }} {{ $unixHref := partial "_funs/add_unix_param.html" $css.RelPermalink }}
<link rel="stylesheet" href="{{ $unixHref }}"> <link rel="stylesheet" href="{{ $unixHref }}">
{{ if .IsPage }}
<style type="text/css">
.post-footer, .flinks-list-footer hr:after {
content: "{{ .Site.Params.postFooter.endLineTip }}";
}
</style>
{{ end }}
<!-- Extend Style -->
<style type="text/css">
{{ partialCached "head/style/global.html" . }}
{{ partial "head/style/plugins.html" . }}
</style>
<!-- Custom Style file -->
{{ $custom := .Scratch.Get "style" }} {{ $custom := .Scratch.Get "style" }}
{{ if $custom }} {{ if $custom }}
{{ $unixHref := partial "_funs/add_unix_param.html" $custom }} {{ $unixHref := partial "_funs/add_unix_param.html" $custom }}

View File

@ -1,2 +1,2 @@
{{ partialCached "scripts/global.html" . }} {{ partialCached "head/script/global.html" . }}
{{ partial "scripts/plugins.html" . }} {{ partial "head/script/plugins.html" . }}

View File

@ -1,3 +1,5 @@
<div class="mermaid" align="{{ .Get "align" | default "center" }}" {{ with .Get "bc" }} style="background: {{ . }}" {{ end }}> <div class="mermaid" align="{{ .Get "align" | default "center" }}" {{ with .Get "bc" }} style="background: {{ . }}" {{ end }}>
{{ safeHTML .Inner }} {{ safeHTML .Inner }}
</div> </div>
{{ .Page.Store.SetInMap "scParams" "mermaid" true }}

View File

@ -20,3 +20,5 @@
{{ with .Get "list-folded" }} list-folded="{{ . }}" {{ end }} {{ with .Get "list-folded" }} list-folded="{{ . }}" {{ end }}
{{ with .Get "list-max-height" }} list-max-height="{{ . }}" {{ end }} {{ with .Get "list-max-height" }} list-max-height="{{ . }}" {{ end }}
></meting-js> ></meting-js>
{{ .Page.Store.SetInMap "scParams" "music" true }}