diff --git a/_config.yml b/_config.yml index ebe6923..f2576dd 100644 --- a/_config.yml +++ b/_config.yml @@ -379,6 +379,8 @@ codeblock: fold: enable: false height: 500 + # Display language name + language: false back2top: enable: true diff --git a/scripts/helpers/next-config.js b/scripts/helpers/next-config.js index c987d35..9ba4659 100644 --- a/scripts/helpers/next-config.js +++ b/scripts/helpers/next-config.js @@ -19,8 +19,7 @@ hexo.extend.helper.register('next_config', function() { exturl : theme.exturl, sidebar : theme.sidebar, hljswrap : theme.highlight.enable && config.highlight.wrap, - copycode : theme.codeblock.copy_button, - fold : theme.codeblock.fold, + codeblock : theme.codeblock, bookmark : theme.bookmark, mediumzoom: theme.mediumzoom, lazyload : theme.lazyload, diff --git a/source/css/_common/components/post/post-footer.styl b/source/css/_common/components/post/post-footer.styl index b71bc6c..ed36d1b 100644 --- a/source/css/_common/components/post/post-footer.styl +++ b/source/css/_common/components/post/post-footer.styl @@ -30,7 +30,7 @@ if (hexo-config('creative_commons.post')) { content: '\f25e'; font-family: 'Font Awesome 6 Brands'; font-size: 200px; - opacity: .1; + opacity: $watermark-opacity; position: absolute; right: -50px; top: -150px; diff --git a/source/css/_common/scaffolding/highlight/copy-code.styl b/source/css/_common/scaffolding/highlight/copy-code.styl index ce42dc1..1d9e53b 100644 --- a/source/css/_common/scaffolding/highlight/copy-code.styl +++ b/source/css/_common/scaffolding/highlight/copy-code.styl @@ -6,6 +6,15 @@ position: relative; } +.code-lang { + font-size: 40px; + line-height: 1; + opacity: $watermark-opacity; + pointer-events: none; + position: absolute; + right: 5px; +} + .copy-btn { color: $black-dim; cursor: pointer; diff --git a/source/css/_variables/base.styl b/source/css/_variables/base.styl index fb28eb8..b2bc748 100644 --- a/source/css/_variables/base.styl +++ b/source/css/_variables/base.styl @@ -415,3 +415,6 @@ $badge-border-radius = 0; $badge-background = $gainsboro; $badge-color = $black-light; $badge-text-shadow = none; + + +$watermark-opacity = .1; diff --git a/source/js/third-party/tags/mermaid.js b/source/js/third-party/tags/mermaid.js index e41efe4..e913c0e 100644 --- a/source/js/third-party/tags/mermaid.js +++ b/source/js/third-party/tags/mermaid.js @@ -13,7 +13,7 @@ document.addEventListener('page:loaded', () => { newElement.innerHTML = element.innerHTML; newElement.className = 'mermaid'; box.appendChild(newElement); - if (CONFIG.copycode.enable) { + if (CONFIG.codeblock.copy_button.enable) { NexT.utils.registerCopyButton(box, box, element.textContent); } const parent = element.parentNode; diff --git a/source/js/utils.js b/source/js/utils.js index 5803d7d..f6bb171 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -89,6 +89,7 @@ NexT.utils = { figure.forEach(element => { // Skip pre > .mermaid for folding and copy button if (element.querySelector('.mermaid')) return; + const languageName = [...element.classList].find(cls => cls !== 'highlight'); if (!inited) { let span = element.querySelectorAll('.code .line span'); if (span.length === 0) { @@ -102,10 +103,10 @@ NexT.utils = { }); } const height = parseInt(window.getComputedStyle(element).height, 10); - const needFold = CONFIG.fold.enable && (height > CONFIG.fold.height); - if (!needFold && !CONFIG.copycode.enable) return; + const needFold = CONFIG.codeblock.fold.enable && (height > CONFIG.codeblock.fold.height); + if (!needFold && !CONFIG.codeblock.copy_button.enable && !CONFIG.codeblock.language) return; let target; - if (CONFIG.hljswrap && CONFIG.copycode.style === 'mac') { + if (CONFIG.hljswrap && CONFIG.codeblock.copy_button.style === 'mac') { target = element; } else { let box = element.querySelector('.code-container'); @@ -130,9 +131,15 @@ NexT.utils = { target.classList.add('unfold'); }); } - if (!inited && CONFIG.copycode.enable) { + if (!inited && CONFIG.codeblock.copy_button.enable) { this.registerCopyButton(target, element); } + if (!inited && CONFIG.codeblock.language && languageName) { + const lang = document.createElement('div'); + lang.className = 'code-lang'; + lang.innerText = languageName.toUpperCase(); + target.insertAdjacentElement('afterbegin', lang); + } }); },