fix(code): repeated initialization of the code tab in the encryption page

This commit is contained in:
Cell
2026-03-21 00:03:07 +08:00
parent b09555981b
commit d9e45154ff
5 changed files with 15 additions and 17 deletions
-5
View File
@@ -532,11 +532,6 @@ pre {
padding-block: 0.875rem;
}
}
// for code tabs, only show the first tab content before JS loaded
&[data-hidden] {
display: none;
}
}
}
+4 -2
View File
@@ -601,7 +601,7 @@ class FixIt {
* init code tabs
*/
initCodeTabs() {
const $codeBlocks = document.querySelectorAll('.code-block[group]');
const $codeBlocks = document.querySelectorAll('.code-block[group]:not([data-tab-init])');
const processed = new Set();
Util.forEach($codeBlocks, ($block) => {
@@ -613,7 +613,6 @@ class FixIt {
// collect consecutive blocks with same group
while ($curr && $curr.classList?.contains('code-block') && $curr.getAttribute('group') === groupName) {
delete $curr.dataset.hidden;
$tabs.push($curr);
processed.add($curr);
$curr = $curr.nextElementSibling;
@@ -701,6 +700,8 @@ class FixIt {
// move block to content
$tab.classList.toggle('active', activeTabIndex === index || defaultActiveTab);
$tab.classList.remove('is-collapsed');
$tab.classList.remove('d-none');
$tab.dataset.tabInit = 'true';
$content.appendChild($tab);
});
@@ -1606,6 +1607,7 @@ class FixIt {
}
const $codeBlocks = $codeTabs.querySelectorAll('.code-block');
$codeBlocks.forEach(($codeBlock) => {
delete $codeBlock.dataset.tabInit;
$codeTabs.parentElement.insertBefore($codeBlock, $codeTabs);
});
$codeTabs.parentElement.removeChild($codeTabs);
+6 -7
View File
@@ -10,9 +10,7 @@
{{- end -}}
{{- if $ok -}}
{{- $pageID := .Page.RelPermalink | default .Page.File.Path -}}
{{- $seed := printf "%s|%s|%s" $pageID .Position .Inner -}}
{{- $group := printf "toggle-%s" (md5 $seed) -}}
{{- $groupId := printf "tab-%s" (md5 (dict "Page" .Page | partial "function/id.html")) -}}
{{- $activeFormat := "" -}}
{{- $raw := strings.TrimSpace .Inner -}}
{{- range $candidate := slice "json" "toml" "yaml" -}}
@@ -24,7 +22,7 @@
{{- end -}}
{{- end -}}
{{- end -}}
{{- $commonAttrsStr := printf ", group=%q" $group -}}
{{- $commonAttrsStr := printf ", group=%q" $groupId -}}
{{- if ne .Attributes.copyable nil -}}
{{- $commonAttrsStr = printf "%s, copyable=%v" $commonAttrsStr .Attributes.copyable -}}
{{- end -}}
@@ -43,8 +41,8 @@
{{- if ne .Attributes.editable nil -}}
{{- $commonAttrsStr = printf "%s, editable=%v" $commonAttrsStr .Attributes.editable -}}
{{- end -}}
{{- if ne .Attributes.before_tabs nil -}}
{{- $commonAttrsStr = printf "%s, before_tabs=%q" $commonAttrsStr .Attributes.before_tabs -}}
{{- with .Attributes.before_tabs -}}
{{- $commonAttrsStr = printf "%s, before_tabs=%q" $commonAttrsStr . -}}
{{- end -}}
{{- $renderText := "" -}}
{{- range $format := slice "toml" "yaml" "json" -}}
@@ -56,7 +54,8 @@
{{- end -}}
{{- $active := cond (eq $format $activeFormat) ", .active" "" -}}
{{- $jsonViewer := cond (eq $format "json") ", enable=false" "" -}}
{{- $block := printf "```%s {name=%q%s%s%s}\n%s\n```\n\n" $format $format $active $jsonViewer $commonAttrsStr $content -}}
{{- $labelName := cond (ne $.Attributes.before_tabs nil) $format (upper $format) -}}
{{- $block := printf "```%s {name=%q%s%s%s}\n%s\n```\n\n" $format $labelName $active $jsonViewer $commonAttrsStr $content -}}
{{- $renderText = add $renderText $block -}}
{{- end -}}
{{- $renderText | .Page.RenderString -}}
+1 -1
View File
@@ -1,4 +1,4 @@
{{- hugo.Store.Set "version" "v0.4.5-20260320034416-9e384b66" -}}
{{- hugo.Store.Set "version" "v0.4.5-20260320160308-b0955598" -}}
{{- .Store.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}
@@ -71,12 +71,14 @@
{{- $isFirst := not (.Page.Store.Get $groupKey) -}}
{{- if $isFirst -}}
{{- .Page.Store.Set $groupKey true -}}
{{- else -}}
{{- $targetClass = add $targetClass " d-none" -}}
{{- end -}}
{{- $hidden := cond $isFirst "" " data-hidden" -}}
{{- $wrapper =
replace $wrapper
(printf `class="%s"` $class)
(printf `class="%s" data-tab-group="%s" data-tab-title="%s"%s` $class $config.group $tabTitle $hidden) -}}
(printf `class="%s" data-tab-title="%s"` $class $tabTitle)
-}}
{{- end -}}
{{- if ne .Options.linenostart nil -}}
{{- $wrapper =