From 9c8c0b6dee5ec95dad5f8e547efb104121a85fd1 Mon Sep 17 00:00:00 2001
From: Cell <1024@lruihao.cn>
Date: Tue, 29 Apr 2025 15:39:54 +0800
Subject: [PATCH] :zap: Perf: optimize echarts plugin warnf content
---
.../_default/_markup/render-codeblock-echarts.html | 8 +++++++-
layouts/partials/init/index.html | 2 +-
layouts/partials/plugin/echarts.html | 14 ++++++++------
layouts/shortcodes/echarts.html | 8 +++++++-
4 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/layouts/_default/_markup/render-codeblock-echarts.html b/layouts/_default/_markup/render-codeblock-echarts.html
index a60d1303..c1fb2e8f 100644
--- a/layouts/_default/_markup/render-codeblock-echarts.html
+++ b/layouts/_default/_markup/render-codeblock-echarts.html
@@ -1,2 +1,8 @@
-{{- dict "Options" .Attributes "Inner" .Inner "Resources" .Page.Resources | partial "plugin/echarts.html" -}}
+{{- dict
+ "Options" .Attributes
+ "Inner" .Inner
+ "Resources" .Page.Resources
+ "Position" .Position
+ | partial "plugin/echarts.html"
+-}}
{{- .Page.Store.Set "hasEcharts" true -}}
diff --git a/layouts/partials/init/index.html b/layouts/partials/init/index.html
index 41f143b1..95cdaf82 100644
--- a/layouts/partials/init/index.html
+++ b/layouts/partials/init/index.html
@@ -1,4 +1,4 @@
-{{- .Scratch.Set "version" "v0.3.20-6eb582fe" -}}
+{{- .Scratch.Set "version" "v0.3.20-0cf0d4f4" -}}
{{- .Scratch.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}
diff --git a/layouts/partials/plugin/echarts.html b/layouts/partials/plugin/echarts.html
index 385eb085..a3c5eca1 100644
--- a/layouts/partials/plugin/echarts.html
+++ b/layouts/partials/plugin/echarts.html
@@ -16,23 +16,25 @@
{{- $content = replaceRE `[\s]+` " " $content -}}
{{- end -}}
{{- if not $content -}}
- {{- warnf "ECharts JS Code is empty, please check the content." -}}
+ {{- warnf "ECharts: JS Code is empty, executing in file %s" $.Position -}}
{{- end -}}
{{ $content | safeJS }}
{{- else -}}
{{ with $data }}
{{- $content = index site.Data.echarts . -}}
{{- if not $content -}}
- {{- warnf "ECharts data not found, please ensure the data file \"/data/echarts/%s.{json|yml|yaml|toml}\" exists." . -}}
+ {{- 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." -}}
+ {{- else with $file -}}
+ {{- warnf "ECharts: no such data file: %s" . -}}
{{- end -}}
+ {{- $content = $content | transform.Unmarshal -}}
+ {{- end -}}
+ {{- if not $content -}}
+ {{- warnf "ECharts: option is empty, executing in file %s" $.Position -}}
{{- end -}}
{{ $content | jsonify }}
{{- end -}}
diff --git a/layouts/shortcodes/echarts.html b/layouts/shortcodes/echarts.html
index d964e86e..0f1564e0 100644
--- a/layouts/shortcodes/echarts.html
+++ b/layouts/shortcodes/echarts.html
@@ -4,5 +4,11 @@
{{- $options = .Get "async" | default false | dict "async" | merge $options -}}
{{- $options = .Get "data" | dict "data" | merge $options -}}
{{- $options = .Get "file" | dict "file" | merge $options -}}
-{{- dict "Options" $options "Inner" .Inner "Resources" .Page.Resources | partial "plugin/echarts.html" -}}
+{{- dict
+ "Options" $options
+ "Inner" .Inner
+ "Resources" .Page.Resources
+ "Position" .Position
+ | partial "plugin/echarts.html"
+-}}
{{- .Page.Store.Set "hasEcharts" true -}}