From 5c74d4318a7ee83bbd79f9754f82b669c2ae266e Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 14 Oct 2025 15:25:23 +0800 Subject: [PATCH] fix: enhance diagram copy button functionality and ensure Echarts visibility on home page --- assets/js/theme.js | 5 ++++- layouts/_markup/render-codeblock-echarts.html | 3 +++ layouts/_partials/init/index.html | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index 8ca3e3b2..49152078 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -527,7 +527,10 @@ class FixIt { this.util.forEach(document.querySelectorAll('.diagram-copy-btn'), ($btn) => { $btn.addEventListener('click', () => { stagingDOM.stage($btn.parentElement.querySelector('template').content.cloneNode(true)) - const code = stagingDOM.contentAsText(); + let code = stagingDOM.contentAsText(); + try { + code = JSON.stringify(JSON.parse(code), null, 2); + } catch {} this.util.copyText(code).then(() => { $btn.toggleAttribute('data-copied', true); setTimeout(() => { diff --git a/layouts/_markup/render-codeblock-echarts.html b/layouts/_markup/render-codeblock-echarts.html index c1fb2e8f..c761ac2b 100644 --- a/layouts/_markup/render-codeblock-echarts.html +++ b/layouts/_markup/render-codeblock-echarts.html @@ -6,3 +6,6 @@ | partial "plugin/echarts.html" -}} {{- .Page.Store.Set "hasEcharts" true -}} +{{- if eq hugo.Context.MarkupScope "home" -}} + {{- site.Home.Store.Set "hasEcharts" true -}} +{{- end -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 1abc6839..068adc3b 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha.2-20251012060036-b4cb5a5a" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha.2-20251014072524-fa94e698" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}}