From 537ad1df3fe7abafad287d4c27324581d16b340c Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Wed, 24 Jul 2024 10:59:01 +0800 Subject: [PATCH] :sparkles: Feat: add config whether to enable the code wrapper Resolved #462 --- assets/css/_partials/_single/_code.scss | 11 ++++++++--- assets/js/theme.js | 4 ++++ hugo.toml | 8 +++++--- layouts/partials/assets.html | 19 +++++++++---------- layouts/partials/single/collection-nav.html | 1 + 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/assets/css/_partials/_single/_code.scss b/assets/css/_partials/_single/_code.scss index e9dc18a2..3f296bae 100644 --- a/assets/css/_partials/_single/_code.scss +++ b/assets/css/_partials/_single/_code.scss @@ -93,6 +93,13 @@ pre:not(.mermaid[data-processed='true']) { @include border-radius($global-border-radius); @include transition(border-radius 0.2s ease); + // delayed loading table-wrapper + & + .table-wrapper { + max-height: 0; + @include border-radius(0 0 $global-border-radius $global-border-radius); + @include details-transition-open; + } + [data-theme='dark'] & { color: $code-info-color-dark; --#{$prefix}bg-code-header: #{darken($code-background-color-dark, 3%)}; @@ -164,10 +171,8 @@ pre:not(.mermaid[data-processed='true']) { // delayed loading table-wrapper .table-wrapper { - max-height: 0; overflow: hidden; - @include border-radius(0 0 $global-border-radius $global-border-radius); - @include details-transition-open; + @include border-radius($global-border-radius); } table { diff --git a/assets/js/theme.js b/assets/js/theme.js index edbc7fd8..3ddc6cb6 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -363,6 +363,10 @@ class FixIt { } initHighlight() { + if (!this.config.code) { + return + } + // if markup.highlight.lineNumbersInTable set to false this.util.forEach(document.querySelectorAll('.highlight > pre.chroma'), ($preChroma) => { const $chroma = document.createElement('div'); $chroma.className = $preChroma.className; diff --git a/hugo.toml b/hugo.toml index 6c4cd5c8..c48603b7 100644 --- a/hugo.toml +++ b/hugo.toml @@ -918,11 +918,13 @@ enableEmoji = true copyTex = true # KaTeX extension mhchem mhchem = true - # Code config + # Code wrapper config [params.page.code] - # whether to show the copy button of the code block + # FixIt 0.3.9 | NEW whether to enable the code wrapper + enable = true + # whether to show the copy button of the code wrapper copy = true - # FixIt 0.2.13 | NEW whether to show the edit button of the code block + # FixIt 0.2.13 | NEW whether to show the edit button of the code wrapper edit = true # the maximum number of lines of displayed code by default maxShownLines = 10 diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index 0d370f53..6074f28f 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -51,17 +51,16 @@ {{- $config = dict "lightgallery" true | merge $config -}} {{- end -}} +{{- /* Code wrapper */ -}} {{- $code := $params.code | default dict -}} -{{- $config = cond (ne $code.maxShownLines nil) $code.maxShownLines 10 | dict "maxShownLines" | dict "code" | merge $config -}} - -{{- /* edit code */ -}} -{{- if ne $code.edit false -}} - {{- $config = dict "editable" true "editLockTitle" (T "assets.editLockTitle") "editUnLockTitle" (T "assets.editUnLockTitle") | dict "code" | merge $config -}} -{{- end -}} - -{{- /* copy code */ -}} -{{- if ne $code.copy false -}} - {{- $config = T "assets.copyToClipboard" | dict "copyTitle" | dict "code" | merge $config -}} +{{- if $code.enable -}} + {{- $config = $code.maxShownLines | dict "maxShownLines" | dict "code" | merge $config -}} + {{- if ne $code.edit false -}} + {{- $config = dict "editable" true "editLockTitle" (T "assets.editLockTitle") "editUnLockTitle" (T "assets.editUnLockTitle") | dict "code" | merge $config -}} + {{- end -}} + {{- if ne $code.copy false -}} + {{- $config = T "assets.copyToClipboard" | dict "copyTitle" | dict "code" | merge $config -}} + {{- end -}} {{- end -}} {{- /* Sharer.js */ -}} diff --git a/layouts/partials/single/collection-nav.html b/layouts/partials/single/collection-nav.html index adbf46e6..144beebc 100644 --- a/layouts/partials/single/collection-nav.html +++ b/layouts/partials/single/collection-nav.html @@ -15,6 +15,7 @@ {{- dict "Collections" $termLink | T "single.includedIn.collections" | strings.FirstUpper | safeHTML }} {{ .Pages.Len -}}