From 0bc94e2a5926c96776520c0326a830b92a16c153 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sun, 14 Apr 2024 13:03:26 -0500 Subject: [PATCH] fix: don't add copy button if already present --- src/Blog/Components/Pages/Post.razor.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Blog/Components/Pages/Post.razor.js b/src/Blog/Components/Pages/Post.razor.js index f11ab7a..9b2490f 100644 --- a/src/Blog/Components/Pages/Post.razor.js +++ b/src/Blog/Components/Pages/Post.razor.js @@ -1,30 +1,15 @@ -let initialized = false; - export function onLoad() { - if (initialized) { - return; - } - init(); } export function onUpdate() { - if (initialized) { - return; - } - init(); } -export function onDispose() { - initialized = false; -} - function init(){ addAnchors(); addClipboard(); Prism.highlightAll(); - initialized = true; } /** @@ -53,6 +38,10 @@ function addClipboard() { const codeBlocks = document.querySelectorAll('pre'); codeBlocks.forEach((block) => { + if (block.querySelector('button.copy-button')) { + return; + } + const button = document.createElement('button'); button.className = 'copy-button'; button.type = 'button';