Feat: add file params for echarts shortcode

This commit is contained in:
Cell
2025-04-28 17:26:29 +08:00
parent 6eb582fef7
commit e663ebbd45
4 changed files with 12 additions and 4 deletions
@@ -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 -}}
+1 -1
View File
@@ -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" . -}}
+8 -1
View File
@@ -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 -}}
<div class="echarts" {{ $attrs | safeHTMLAttr }}></div>
{{- $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." -}}
+2 -1
View File
@@ -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 -}}