From e663ebbd4557018670728b4905ebd5abd25de4fa Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Mon, 28 Apr 2025 17:26:29 +0800 Subject: [PATCH] :sparkles: Feat: add `file` params for echarts shortcode --- layouts/_default/_markup/render-codeblock-echarts.html | 2 +- layouts/partials/init/index.html | 2 +- layouts/partials/plugin/echarts.html | 9 ++++++++- layouts/shortcodes/echarts.html | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/layouts/_default/_markup/render-codeblock-echarts.html b/layouts/_default/_markup/render-codeblock-echarts.html index 1a519c8e..a60d1303 100644 --- a/layouts/_default/_markup/render-codeblock-echarts.html +++ b/layouts/_default/_markup/render-codeblock-echarts.html @@ -1,2 +1,2 @@ -{{- dict "Options" .Attributes "Inner" .Inner | partial "plugin/echarts.html" -}} +{{- dict "Options" .Attributes "Inner" .Inner "Resources" .Page.Resources | partial "plugin/echarts.html" -}} {{- .Page.Store.Set "hasEcharts" true -}} diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html index 7b24011a..41f143b1 100644 --- a/layouts/partials/init/index.html +++ b/layouts/partials/init/index.html @@ -1,4 +1,4 @@ -{{- .Scratch.Set "version" "v0.3.20-f7a9c52a" -}} +{{- .Scratch.Set "version" "v0.3.20-6eb582fe" -}} {{- .Scratch.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/partials/plugin/echarts.html b/layouts/partials/plugin/echarts.html index cf0008f4..385eb085 100644 --- a/layouts/partials/plugin/echarts.html +++ b/layouts/partials/plugin/echarts.html @@ -4,10 +4,14 @@ {{- $js := .Options.js | default false -}} {{- $async := .Options.async | default false -}} {{- $data := .Options.data -}} +{{- $file := .Options.file -}} {{- $attrs := printf `style="width: %v; height: %v;"` $width $height -}}
{{- $content := strings.TrimSpace .Inner -}} -{{- if $js -}} +{{- if $js | or (hasSuffix $file ".js") -}} + {{- with dict "Path" $file "Resources" .Resources | partial "function/resource.html" }} + {{- $content = .Content -}} + {{- end }} {{- if hugo.IsProduction -}} {{- $content = replaceRE `[\s]+` " " $content -}} {{- end -}} @@ -22,6 +26,9 @@ {{- warnf "ECharts data not found, please ensure the data file \"/data/echarts/%s.{json|yml|yaml|toml}\" exists." . -}} {{- end -}} {{- else -}} + {{- with dict "Path" $file "Resources" .Resources | partial "function/resource.html" }} + {{- $content = .Content -}} + {{- end }} {{- $content = $content | transform.Unmarshal -}} {{- if not $content -}} {{- warnf "ECharts option is empty, please check the content." -}} diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html index 40a6a2cf..d964e86e 100644 --- a/layouts/shortcodes/echarts.html +++ b/layouts/shortcodes/echarts.html @@ -3,5 +3,6 @@ {{- $options = .Get "js" | default false | dict "js" | merge $options -}} {{- $options = .Get "async" | default false | dict "async" | merge $options -}} {{- $options = .Get "data" | dict "data" | merge $options -}} -{{- dict "Options" $options "Inner" .Inner | partial "plugin/echarts.html" -}} +{{- $options = .Get "file" | dict "file" | merge $options -}} +{{- dict "Options" $options "Inner" .Inner "Resources" .Page.Resources | partial "plugin/echarts.html" -}} {{- .Page.Store.Set "hasEcharts" true -}}