2025-02-13 23:04:40 +01:00
|
|
|
import fs from "fs"
|
|
|
|
import path from "path"
|
2025-02-15 15:54:19 +01:00
|
|
|
import { remark } from "remark"
|
|
|
|
import html from "remark-html"
|
2025-05-27 17:16:44 +02:00
|
|
|
import * as gfm from "remark-gfm"
|
2025-02-15 15:54:19 +01:00
|
|
|
import dynamic from "next/dynamic"
|
|
|
|
import parse from "html-react-parser"
|
2025-02-16 00:09:53 +01:00
|
|
|
import Footer from "@/components/footer"
|
2025-05-27 17:16:44 +02:00
|
|
|
import RSSLink from "@/components/rss-link"
|
2025-02-14 18:11:45 +01:00
|
|
|
|
2025-05-27 17:16:44 +02:00
|
|
|
// Import CopyableCode dynamically to avoid SSR issues
|
2025-02-15 15:54:19 +01:00
|
|
|
const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false })
|
|
|
|
|
2025-02-15 16:06:47 +01:00
|
|
|
async function getChangelogContent() {
|
2025-02-14 17:54:52 +01:00
|
|
|
try {
|
2025-02-15 16:06:47 +01:00
|
|
|
const changelogPath = path.join(process.cwd(), "..", "CHANGELOG.md")
|
2025-02-15 16:27:43 +01:00
|
|
|
|
|
|
|
if (!fs.existsSync(changelogPath)) {
|
2025-05-27 17:16:44 +02:00
|
|
|
console.error("❌ CHANGELOG.md file not found.")
|
|
|
|
return "<p class='text-red-600'>Error: CHANGELOG.md file not found</p>"
|
2025-02-15 16:27:43 +01:00
|
|
|
}
|
|
|
|
|
2025-02-15 16:06:47 +01:00
|
|
|
const fileContents = fs.readFileSync(changelogPath, "utf8")
|
2025-02-15 15:54:19 +01:00
|
|
|
|
2025-05-27 17:16:44 +02:00
|
|
|
// Add remark-gfm to support images, tables and other advanced Markdown elements
|
2025-02-15 16:27:43 +01:00
|
|
|
const result = await remark()
|
2025-05-27 17:16:44 +02:00
|
|
|
.use(gfm.default || gfm) // Safe handling of remark-gfm
|
2025-02-15 16:27:43 +01:00
|
|
|
.use(html)
|
|
|
|
.process(fileContents)
|
|
|
|
|
2025-02-15 15:54:19 +01:00
|
|
|
return result.toString()
|
2025-02-14 17:54:52 +01:00
|
|
|
} catch (error) {
|
2025-05-27 17:16:44 +02:00
|
|
|
console.error("❌ Error reading CHANGELOG.md file", error)
|
|
|
|
return "<p class='text-red-600'>Error: Could not load changelog content.</p>"
|
2025-02-14 17:54:52 +01:00
|
|
|
}
|
2025-02-13 23:04:40 +01:00
|
|
|
}
|
|
|
|
|
2025-05-27 17:16:44 +02:00
|
|
|
// Clean backticks in inline code fragments
|
2025-02-15 15:54:19 +01:00
|
|
|
function cleanInlineCode(content: string) {
|
|
|
|
return content.replace(/<code>(.*?)<\/code>/g, (_, codeContent) => {
|
|
|
|
return `<code class="bg-gray-200 text-gray-900 px-1 rounded">${codeContent.replace(/^`|`$/g, "")}</code>`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-05-27 17:16:44 +02:00
|
|
|
// Wrap code blocks with CopyableCode component
|
2025-02-15 15:54:19 +01:00
|
|
|
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 <CopyableCode code={codeContent} />
|
|
|
|
}
|
|
|
|
}
|
2025-05-27 17:16:44 +02:00
|
|
|
},
|
2025-02-15 15:54:19 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2025-02-15 16:06:47 +01:00
|
|
|
export default async function ChangelogPage() {
|
|
|
|
const changelogContent = await getChangelogContent()
|
2025-05-27 17:16:44 +02:00
|
|
|
const cleanedInlineCode = cleanInlineCode(changelogContent) // First clean inline code
|
|
|
|
const parsedContent = wrapCodeBlocksWithCopyable(cleanedInlineCode) // Then apply JSX to code blocks
|
2025-02-13 23:04:40 +01:00
|
|
|
|
2025-02-14 12:24:18 +01:00
|
|
|
return (
|
2025-02-15 15:54:19 +01:00
|
|
|
<div className="min-h-screen bg-white text-gray-900">
|
2025-05-27 17:16:44 +02:00
|
|
|
<div className="container mx-auto px-4 py-16" style={{ maxWidth: "980px" }}>
|
|
|
|
{" "}
|
|
|
|
{/* Exact adjustment like GitHub */}
|
2025-02-15 16:06:47 +01:00
|
|
|
<h1 className="text-4xl font-bold mb-8">Changelog</h1>
|
2025-05-27 17:16:44 +02:00
|
|
|
{/* RSS Link Component */}
|
|
|
|
<RSSLink />
|
|
|
|
<div className="prose max-w-none text-[16px]">{parsedContent}</div> {/* Text adjusted to 16px */}
|
2025-02-14 17:54:52 +01:00
|
|
|
</div>
|
2025-02-16 00:09:53 +01:00
|
|
|
<Footer />
|
2025-02-13 23:04:40 +01:00
|
|
|
</div>
|
|
|
|
)
|
2025-02-14 17:09:21 +01:00
|
|
|
}
|