chore: added copy button 60fcd3e2
Steve · 2026-01-03 16:28 1 file(s) · +26 −1
src/pages/pds/index.astro +26 −1
74 74
          <article class="max-w-2xl mx-auto">
75 75
            <p class="mb-2">${post.text}</p>
76 76
            ${imagesHTML}
77 -
            <time class="text-sm text-gray-500 mt-2 block">${createdAt}</time>
77 +
            <div class="flex items-center justify-between mt-4">
78 +
              <time class="text-sm text-gray-500">${createdAt}</time>
79 +
              <button
80 +
                id="share-btn"
81 +
                class="text-sm text-gray-500 hover:text-gray-700 transition-colors"
82 +
                onclick="copyURL()"
83 +
              >
84 +
                Share
85 +
              </button>
86 +
            </div>
78 87
          </article>
79 88
        `;
80 89
87 96
    }
88 97
89 98
    fetchPost();
99 +
100 +
    // Copy URL function
101 +
    window.copyURL = function() {
102 +
      const url = window.location.href;
103 +
      navigator.clipboard.writeText(url).then(() => {
104 +
        const btn = document.getElementById('share-btn');
105 +
        const originalText = btn.textContent;
106 +
        btn.textContent = 'Copied!';
107 +
        setTimeout(() => {
108 +
          btn.textContent = originalText;
109 +
        }, 2000);
110 +
      }).catch(err => {
111 +
        console.error('Failed to copy URL:', err);
112 +
        alert('Failed to copy URL');
113 +
      });
114 +
    };
90 115
  </script>
91 116
92 117
</PageLayout>