import fs from "fs" import path from "path" import { remark } from "remark" import html from "remark-html" import * as gfm from "remark-gfm" import dynamic from "next/dynamic" import parse from "html-react-parser" import Footer from "@/components/footer" import RSSLink from "@/components/rss-link" // Import CopyableCode dynamically to avoid SSR issues const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false }) async function getChangelogContent() { try { const changelogPath = path.join(process.cwd(), "..", "CHANGELOG.md") if (!fs.existsSync(changelogPath)) { console.error("❌ CHANGELOG.md file not found.") return "

Error: CHANGELOG.md file not found

" } const fileContents = fs.readFileSync(changelogPath, "utf8") // Add remark-gfm to support images, tables and other advanced Markdown elements const result = await remark() .use(gfm.default || gfm) // Safe handling of remark-gfm .use(html) .process(fileContents) return result.toString() } catch (error) { console.error("❌ Error reading CHANGELOG.md file", error) return "

Error: Could not load changelog content.

" } } // Clean backticks in inline code fragments function cleanInlineCode(content: string) { return content.replace(/(.*?)<\/code>/g, (_, codeContent) => { return `${codeContent.replace(/^`|`$/g, "")}` }) } // Wrap code blocks with CopyableCode component function wrapCodeBlocksWithCopyable(content: string) { return parse(content, { replace: (domNode: any) => { if (domNode.name === "pre" && domNode.children.length > 0) { const codeElement = domNode.children.find((child: any) => child.name === "code") if (codeElement) { const codeContent = codeElement.children[0]?.data?.trim() || "" return } } }, }) } export default async function ChangelogPage() { const changelogContent = await getChangelogContent() const cleanedInlineCode = cleanInlineCode(changelogContent) // First clean inline code const parsedContent = wrapCodeBlocksWithCopyable(cleanedInlineCode) // Then apply JSX to code blocks return (
{" "} {/* Exact adjustment like GitHub */}

Changelog

{/* RSS Link Component */}
{parsedContent}
{/* Text adjusted to 16px */}
) }