From 606283689272826ebae37621410e381fa8ecb287 Mon Sep 17 00:00:00 2001 From: Fatih Date: Sun, 20 Sep 2026 04:40:35 +0300 Subject: [PATCH 1/2] feat(blog): copy a code block without selecting it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 87 of the 104 posts carry code — connection strings, compose fragments, SQL — and the point of publishing them is that someone runs them. Selecting a multi-line block by hand was the one part of that the page controlled and was not helping with. The button is injected at runtime rather than rendered into the markup. The alternative is a `data-copy` attribute holding a second copy of every block, which would roughly double the weight of a code-heavy page to save a few lines of script; reading `textContent` at click time also guarantees the text is the code the reader is looking at. With JavaScript off the blocks render exactly as before. The clipboard write and its execCommand fallback moved to scripts/clipboard.ts so the two callers cannot drift on the part that is easy to get subtly wrong off https. Hidden until hover for the mouse, and always visible where there is no hover — an affordance that only appears on hover does not exist on a phone. --- src/pages/blog/[...id].astro | 48 +++++++++++++++++++++++++++++ src/scripts/clipboard.ts | 25 +++++++++++++++ src/scripts/code-copy.ts | 59 ++++++++++++++++++++++++++++++++++++ src/scripts/copy.ts | 26 ++-------------- tests/post-relations.test.ts | 23 ++++++++++++++ 5 files changed, 157 insertions(+), 24 deletions(-) create mode 100644 src/scripts/clipboard.ts create mode 100644 src/scripts/code-copy.ts diff --git a/src/pages/blog/[...id].astro b/src/pages/blog/[...id].astro index 00a4337..4d95aa6 100644 --- a/src/pages/blog/[...id].astro +++ b/src/pages/blog/[...id].astro @@ -171,6 +171,10 @@ const schema = [ + +