diff options
author | WingLim <643089849@qq.com> | 2021-09-27 08:50:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-27 08:50:45 +0300 |
commit | c16e6499a7cd8a1d4bf63125e2bdd753168ea7c1 (patch) | |
tree | 97ed3011feb9904893e1c7785753e60a6f0c4c05 | |
parent | 8ec313c01056504b578dab7b42e3beef26b1f170 (diff) |
feat: auto detect lineNos (#46)v1.9.3
-rw-r--r-- | assets/ts/copyButton.ts | 4 | ||||
-rw-r--r-- | assets/ts/features.ts | 4 | ||||
-rw-r--r-- | exampleSite/config.yaml | 5 | ||||
-rw-r--r-- | layouts/partials/footer/footer.html | 2 |
4 files changed, 4 insertions, 11 deletions
diff --git a/assets/ts/copyButton.ts b/assets/ts/copyButton.ts index 360951b..e05458b 100644 --- a/assets/ts/copyButton.ts +++ b/assets/ts/copyButton.ts @@ -5,7 +5,7 @@ const codeBlocks = document.querySelectorAll('.article-post .highlight'); const copyText = `Copy`, copiedText = `Copied!`; -export let renderCopyButton = function(enableLineNos: boolean) { +export let renderCopyButton = function() { codeBlocks.forEach(codeBlock => { const copyButton = document.createElement('button') copyButton.innerHTML = copyText @@ -16,7 +16,7 @@ export let renderCopyButton = function(enableLineNos: boolean) { // This theme's code block has line number, so the second is where the // real code locate let codeIndex = 0 - if (enableLineNos) { + if (pre.length == 2) { codeIndex = 1 } const code = pre[codeIndex].textContent; diff --git a/assets/ts/features.ts b/assets/ts/features.ts index 56c0b62..ad27b9a 100644 --- a/assets/ts/features.ts +++ b/assets/ts/features.ts @@ -3,10 +3,8 @@ import { renderCopyButton } from "ts/copyButton" import { renderFootnotes } from "ts/footnotes" let enableFootnotes = false -let enableLineNos = false if (document.currentScript) { enableFootnotes = document.currentScript.dataset.enableFootnotes == 'true' - enableLineNos = document.currentScript.dataset.enableLinenos == 'true' } const init = () => { @@ -14,7 +12,7 @@ const init = () => { if (enableFootnotes) { renderFootnotes() } - renderCopyButton(enableLineNos) + renderCopyButton() } window.addEventListener('load', () => { diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index 87ba93d..f9c4b6b 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -16,11 +16,6 @@ params: # Enable float footnotes. # Default to true enableFootnotes: true - - # Enable line numbers, it need to set the same value with - # markup.hightlight.lineNos - # Default to false - enableLineNos: true siteName: "Hugo Tania is Amazing" siteDesc: "Hugo is Absurdly Fast!" diff --git a/layouts/partials/footer/footer.html b/layouts/partials/footer/footer.html index efe8e9c..b74a63a 100644 --- a/layouts/partials/footer/footer.html +++ b/layouts/partials/footer/footer.html @@ -37,5 +37,5 @@ {{ $features := resources.Get "ts/features.ts" | js.Build $opts | fingerprint }} <script defer src="{{ $features.RelPermalink }}" data-enable-footnotes="{{ .Site.Params.enableFootnotes | default true }}" - data-enable-lineNos="{{ .Site.Params.enableLineNos | default false }}"></script> + ></script> </footer> |