From a77a31f4c97c7633c6207015111fc80769eb78d2 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 9 Feb 2026 12:09:16 -0500 Subject: [PATCH] Fix share links: use external URL (docs.jongsma.me), fix copy button, add copy on existing shares --- templates/document.html | 49 ++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/templates/document.html b/templates/document.html index c3b5d85..ac343eb 100644 --- a/templates/document.html +++ b/templates/document.html @@ -244,7 +244,7 @@

Share link created!

- +
@@ -413,6 +413,30 @@ function closeShareModal() { document.getElementById('share-modal').classList.add('hidden'); } + const EXTERNAL_BASE = 'https://docs.jongsma.me'; + + function copyToClipboard(text, btn) { + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(() => showCopied(btn)); + } else { + const ta = document.createElement('textarea'); + ta.value = text; + ta.style.position = 'fixed'; + ta.style.opacity = '0'; + document.body.appendChild(ta); + ta.select(); + document.execCommand('copy'); + document.body.removeChild(ta); + showCopied(btn); + } + } + function showCopied(btn) { + if (!btn) return; + const orig = btn.textContent; + btn.textContent = 'Copied!'; + setTimeout(() => btn.textContent = orig, 1500); + } + async function createShare() { const days = parseInt(document.getElementById('share-days').value); const res = await fetch('/api/share/{{.Document.ID}}', { @@ -422,15 +446,15 @@ }); if (res.ok) { const data = await res.json(); - const fullUrl = window.location.origin + data.url; + const fullUrl = EXTERNAL_BASE + data.url; document.getElementById('share-url').value = fullUrl; document.getElementById('share-result').classList.remove('hidden'); loadShares(); } } - function copyShareUrl() { + function copyShareUrl(btn) { const input = document.getElementById('share-url'); - navigator.clipboard.writeText(input.value); + copyToClipboard(input.value, btn); } async function loadShares() { const res = await fetch('/api/shares/{{.Document.ID}}'); @@ -440,15 +464,20 @@ list.innerHTML = '

No active shares

'; return; } - list.innerHTML = shares.map(s => ` + list.innerHTML = shares.map(s => { + const url = EXTERNAL_BASE + '/s/' + s.Token; + return `
-
- ${window.location.origin}/s/${s.Token} +
+ ${url} ${s.ExpiresAt ? 'expires ' + s.ExpiresAt : 'permanent'}
- -
- `).join(''); +
+ + +
+
`; + }).join(''); } async function revokeShare(token) { await fetch('/api/share/' + token, {method: 'DELETE'});