Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/WingLim/hugo-tania.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWingLim <winglim@qq.com>2021-09-25 11:52:42 +0300
committerWingLim <winglim@qq.com>2021-09-25 11:52:42 +0300
commitcad48509a4fa1ebd09468d5530dfe38e3d7c48dc (patch)
tree1deda96fb6a796c70e1638edea670ce20a3c042d
parenta0022251d97947d47d769291061dd72e9cadd3a1 (diff)
fix: copy content without line numbers
-rw-r--r--assets/ts/copyButton.ts8
-rw-r--r--assets/ts/features.ts4
-rw-r--r--exampleSite/config.yaml5
-rw-r--r--layouts/partials/footer/footer.html4
4 files changed, 17 insertions, 4 deletions
diff --git a/assets/ts/copyButton.ts b/assets/ts/copyButton.ts
index 03cd6e6..360951b 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() {
+export let renderCopyButton = function(enableLineNos: boolean) {
codeBlocks.forEach(codeBlock => {
const copyButton = document.createElement('button')
copyButton.innerHTML = copyText
@@ -15,7 +15,11 @@ export let renderCopyButton = function() {
const pre = codeBlock.getElementsByTagName('pre');
// This theme's code block has line number, so the second is where the
// real code locate
- const code = pre[1].textContent;
+ let codeIndex = 0
+ if (enableLineNos) {
+ codeIndex = 1
+ }
+ const code = pre[codeIndex].textContent;
copyButton.addEventListener('click', () => {
navigator.clipboard.writeText(code)
diff --git a/assets/ts/features.ts b/assets/ts/features.ts
index ad27b9a..56c0b62 100644
--- a/assets/ts/features.ts
+++ b/assets/ts/features.ts
@@ -3,8 +3,10 @@ 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 = () => {
@@ -12,7 +14,7 @@ const init = () => {
if (enableFootnotes) {
renderFootnotes()
}
- renderCopyButton()
+ renderCopyButton(enableLineNos)
}
window.addEventListener('load', () => {
diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml
index 9670464..46c7fee 100644
--- a/exampleSite/config.yaml
+++ b/exampleSite/config.yaml
@@ -16,6 +16,11 @@ 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 true
+ enableLineNos: true
siteName: "Hugo Tania is Amazing"
siteDesc: "Hugo is Absurdly Fast!"
author: "Hugo Tania"
diff --git a/layouts/partials/footer/footer.html b/layouts/partials/footer/footer.html
index a473296..efe8e9c 100644
--- a/layouts/partials/footer/footer.html
+++ b/layouts/partials/footer/footer.html
@@ -35,5 +35,7 @@
{{- end }}
{{- $opts := dict "minify" hugo.IsProduction -}}
{{ $features := resources.Get "ts/features.ts" | js.Build $opts | fingerprint }}
- <script defer src="{{ $features.RelPermalink }}" data-enable-footnotes="{{ .Site.Params.enableFootnotes | default true }}"></script>
+ <script defer src="{{ $features.RelPermalink }}"
+ data-enable-footnotes="{{ .Site.Params.enableFootnotes | default true }}"
+ data-enable-lineNos="{{ .Site.Params.enableLineNos | default false }}"></script>
</footer>