Update page.tsx

This commit is contained in:
MacRimi 2025-02-14 18:21:58 +01:00 committed by GitHub
parent 5620fe52f1
commit c50bde5ce9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,35 +1,14 @@
import fs from "fs" import fs from "fs"
import path from "path" import path from "path"
import { remark } from "remark"
import html from "remark-html"
function markdownToHtml(markdown: string): string {
return markdown
.replace(/^### (.*$)/gim, "<h3>$1</h3>")
.replace(/^## (.*$)/gim, "<h2>$1</h2>")
.replace(/^# (.*$)/gim, "<h1>$1</h1>")
.replace(/\*\*(.*?)\*\*/gim, "<b>$1</b>")
.replace(/\*(.*?)\*/gim, "<i>$1</i>")
.replace(/`(.*?)`/gim, "<code>$1</code>")
.replace(/^- (.*$)/gim, "<ul><li>$1</li></ul>")
.replace(/\n/g, "<br />");
}
async function getChangelog() { async function getChangelog() {
const changelogPath = path.join(process.cwd(), "..", "CHANGELOG.md") const changelogPath = path.join(process.cwd(), "..", "CHANGELOG.md")
try { try {
const fileContents = fs.readFileSync(changelogPath, "utf8") const fileContents = fs.readFileSync(changelogPath, "utf8")
return fileContents
// Convertimos Markdown a HTML manualmente
const formattedContent = markdownToHtml(fileContents)
// Usamos remark-html como último paso
const result = await remark().use(html).process(formattedContent)
return result.toString()
} catch (error) { } catch (error) {
console.error("Error reading changelog file:", error) console.error("Error reading changelog file:", error)
return "<p>Changelog content not found.</p>" return "Changelog content not found."
} }
} }
@ -37,10 +16,12 @@ export default async function ChangelogPage() {
const changelogContent = await getChangelog() const changelogContent = await getChangelog()
return ( return (
<div className="bg-white text-gray-900"> <div className="bg-white text-gray-900 min-h-screen">
<div className="container mx-auto px-4 py-16 max-w-4xl"> <div className="container mx-auto px-4 py-16 max-w-4xl">
<h1 className="text-4xl font-bold mb-8">Changelog</h1> <h1 className="text-4xl font-bold mb-8">Changelog</h1>
<div className="prose prose-lg max-w-none" dangerouslySetInnerHTML={{ __html: changelogContent }} /> <pre className="bg-gray-100 p-4 border border-gray-300 rounded-md whitespace-pre-wrap">
{changelogContent}
</pre>
</div> </div>
</div> </div>
) )