Link previews
Turn a pasted URL into a link, a mention chip, a bookmark card, or an embed.
When a paste is a single http(s) URL, the link-preview add-on asks what to make of it: Link, Mention, Bookmark, or Embed (when the media add-on's embedAllowlist allows that host). Escape inserts a plain link; typing first drops the question. Full behaviour, including the example server's unfurl endpoint, is in Blocks → Link previews.
Install
npx shadcn@latest add https://blockcn.com/r/link-preview.jsonUse it
"use client";
import { Editor } from "@/components/editor/Editor";
import { useEditor } from "@/components/editor/useEditor";
import { createBlockcnEditor } from "@/components/editor/preset";
import { linkPreview } from "@/components/editor/linkPreview/linkPreviewAddon";
const kit = createBlockcnEditor({
addons: [
linkPreview({
fetchMetadata: async (url) => {
const response = await fetch(`/api/unfurl?url=${encodeURIComponent(url)}`);
return response.ok ? response.json() : {};
},
}),
],
});
export function BlockEditor() {
const editor = useEditor({ extensions: kit.extensions });
return (
<Editor editor={editor}>
<Editor.Frame>
<Editor.Content />
<Editor.Chrome>
<Editor.SideMenu />
<Editor.FormattingToolbar />
{kit.chrome}
</Editor.Chrome>
</Editor.Frame>
</Editor>
);
}kit.chrome includes the choice menu (LinkPreviewMenu). Without createBlockcnEditor, spread createLinkPreviewExtensions({ fetchMetadata }) from @/components/editor/linkPreview/linkPreview and render <LinkPreviewMenu /> inside Editor.Chrome.
Options
| Option | ||
|---|---|---|
fetchMetadata(url) | optional | Returns { title, description, image, favicon, siteName } (any subset). The editor never fetches the page itself. Without it, or when it fails, the hostname is the title. |