Original post: Building a share widget with the Clipboard API
Series: Part of How this blog was built — documenting every decision that shaped this site.
Sharing a post is one of those interactions that looks trivial to implement, yet has
a few subtle corners once you get into it, particularly around the copy-to-clipboard
flow and URL construction for each channel.
SharePost.astro is a small component that covers four share targets: LinkedIn,
Reddit, email, and a copy-link button. It has no external dependencies, no JavaScript
frameworks, and no tracking.
The component props
interface Props { title : string ; url : string ; vertical ?: boolean ; variant ?: " default " | " hero " | " sidebar " | " menu " ; }
Enter fullscreen mode
Exit fullscreen mode
url is the fully qualified canonical URL of the post, passed in from
PageHero.astro as Astro.url.href . vertical flips the layout to a
column stack for sidebar placement.…