@@ -577,9 +577,9 @@ const {
577577</script >
578578
579579<!-- Copy code button functionality - deferred for performance -->
580- <script is:inline defer >
580+ <!-- < script is:inline defer>
581581 function addCopyCodeButtons() {
582- let copyButtonLabel = "✂️ copy";
582+ let copyButtonLabel = "copy";
583583 let codeBlocks = Array.from(document.querySelectorAll("pre"));
584584
585585 async function copyCode(codeBlock, copyButton) {
@@ -588,7 +588,7 @@ const {
588588 const textToCopy = codeText.replace(buttonText, "");
589589
590590 await navigator.clipboard.writeText(textToCopy);
591- copyButton.innerText = "✅ copied!";
591+ copyButton.innerText = "copied!";
592592
593593 setTimeout(() => {
594594 copyButton.innerText = copyButtonLabel;
@@ -617,8 +617,47 @@ const {
617617
618618document.addEventListener("DOMContentLoaded", () => addCopyCodeButtons());
619619document.addEventListener("astro:after-swap", () => addCopyCodeButtons());
620+ </script> -->
621+
622+ <script is:inline defer >
623+ function addCopyCodeButtons() {
624+ const copyButtonLabel = "copy";
625+ const codeBlocks = Array.from(document.querySelectorAll("pre"));
626+
627+ async function copyCode(codeBlock, copyButton) {
628+ // Exclude the button text by cloning and removing button
629+ const clone = codeBlock.cloneNode(true);
630+ const button = clone.querySelector(".copy-code");
631+ if (button) button.remove();
632+
633+ const textToCopy = clone.innerText;
634+ await navigator.clipboard.writeText(textToCopy);
635+
636+ copyButton.innerText = "copied!";
637+ setTimeout(() => (copyButton.innerText = copyButtonLabel), 2000);
638+ }
639+
640+ for (let pre of codeBlocks) {
641+ if (pre.querySelector(".copy-code")) continue;
642+
643+ const copyButton = document.createElement("button");
644+ copyButton.className = "copy-code";
645+ copyButton.innerText = copyButtonLabel;
646+
647+ pre.style.position = "relative";
648+ pre.appendChild(copyButton);
649+
650+ copyButton.addEventListener("click", async () => {
651+ await copyCode(pre, copyButton);
652+ });
653+ }
654+ }
655+
656+ document.addEventListener("DOMContentLoaded", addCopyCodeButtons);
657+ document.addEventListener("astro:after-swap", addCopyCodeButtons);
620658</script >
621659
660+
622661<!-- Analytics Testing and Debugging (Development Only) -->
623662{ isDevelopment && (
624663 <script is :inline define :vars = { {
0 commit comments