From c7a00b6af188097785f4dd8bcb6959775e3b4933 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Mon, 2 Mar 2026 17:03:23 +0100 Subject: feat: copy changelog release as markdown --- .../changelog/components/copy-markdown-button.tsx | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 apps/web/src/app/changelog/components/copy-markdown-button.tsx (limited to 'apps/web/src/app/changelog/components') diff --git a/apps/web/src/app/changelog/components/copy-markdown-button.tsx b/apps/web/src/app/changelog/components/copy-markdown-button.tsx new file mode 100644 index 00000000..33108bfc --- /dev/null +++ b/apps/web/src/app/changelog/components/copy-markdown-button.tsx @@ -0,0 +1,68 @@ +"use client"; + +import { useState } from "react"; +import { CheckIcon, ClipboardIcon } from "lucide-react"; +import { getSectionTitle, groupAndOrderChanges } from "../utils"; +import type { Change } from "../utils"; +import { cn } from "@/utils/ui"; +import { Button } from "@/components/ui/button"; + +function buildMarkdown({ + description, + changes, +}: { + description?: string; + changes: Change[]; +}): string { + const lines: string[] = []; + + if (description) { + lines.push(description, ""); + } + + const { grouped, orderedTypes } = groupAndOrderChanges({ changes }); + + for (const type of orderedTypes) { + lines.push(`## ${getSectionTitle(type)}`); + for (const change of grouped[type]) { + lines.push(`- ${change.text}`); + } + lines.push(""); + } + + return lines.join("\n").trimEnd(); +} + +export function CopyMarkdownButton({ + description, + changes, +}: { + description?: string; + changes: Change[]; +}) { + const [copied, setCopied] = useState(false); + + const handleCopy = async () => { + const markdown = buildMarkdown({ description, changes }); + await navigator.clipboard.writeText(markdown); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + }; + + return ( + + ); +} -- cgit v1.3.1