@plugdash/shortlink
shortlink
What it does
On publish, generates a short code for each post and stores the
mapping in KV under shortlink:[code]:data. Registers a
redirect route so /l/[code] sends visitors to the full
post URL. Ships CopyLink.astro with three variants and a
green check confirmation on copy.
Install
npm install @plugdash/shortlink Register
Open astro.config.mjs at the root of your Astro project.
Import the plugin at the top, then add it to the plugins
array of the emdash() integration - the one that sits
inside Astro's top-level integrations array:
// astro.config.mjs
import { defineConfig } from "astro/config"
import emdash from "emdash/astro"
import { shortlinkPlugin } from "@plugdash/shortlink"
export default defineConfig({
integrations: [
emdash({
plugins: [
shortlinkPlugin({ autoCreate: true }),
],
}),
],
}) Add the component
---
import CopyLink from "@plugdash/shortlink/CopyLink.astro"
---
<CopyLink post={post} /> Live demo
Props
| prop | type | default | description |
|---|---|---|---|
post | EmDash content item | Required | |
variant | "circle" | "pill" | "inline" | "circle" | Visual style |
CSS custom properties
| token | description |
|---|---|
--plugdash-copy-color | Icon colour |
--plugdash-copy-size | Button size |
For agents
After install, publish a post and verify
post.data.metadata.shortlink.url is populated. Hit the
short URL in a browser and confirm it redirects to the canonical post.
Codes are generated at publish time, not lazily.