42 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-02-13 17:28:49 +01:00
import fs from "fs"
import path from "path"
import { remark } from "remark"
import html from "remark-html"
2025-02-14 10:46:02 +01:00
2025-02-13 17:28:49 +01:00
async function getGuideContent(slug: string) {
2025-02-15 12:56:14 +01:00
const guidePath = path.join(process.cwd(), "..", "guides", `${slug}.md`)
const fileContents = fs.readFileSync(guidePath, "utf8")
2025-02-13 17:28:49 +01:00
2025-02-15 14:26:09 +01:00
const result = await remark().use(html).process(fileContents)
2025-02-15 12:56:14 +01:00
return result.toString()
2025-02-13 17:28:49 +01:00
}
2025-02-15 12:56:14 +01:00
export async function generateStaticParams() {
const guideFiles = fs.readdirSync(path.join(process.cwd(), "..", "guides"))
return guideFiles.map((file) => ({
slug: file.replace(/\.md$/, ""),
}))
2025-02-15 12:40:28 +01:00
}
2025-02-15 11:54:33 +01:00
export default async function GuidePage({ params }: { params: { slug: string } }) {
2025-02-15 12:56:14 +01:00
const guideContent = await getGuideContent(params.slug)
2025-02-13 23:04:40 +01:00
2025-02-15 14:26:09 +01:00
// Función para envolver los bloques de código con CopyableCode
2025-02-15 13:24:22 +01:00
const wrapCodeBlocks = (content: string) => {
return content.replace(
2025-02-15 14:06:09 +01:00
/<pre><code>([\s\S]*?)<\/code><\/pre>/g,
(match, code) => `<CopyableCode code="${encodeURIComponent(code.trim())}" />`,
2025-02-15 13:24:22 +01:00
)
}
const wrappedContent = wrapCodeBlocks(guideContent)
2025-02-14 11:05:58 +01:00
return (
2025-02-15 13:24:22 +01:00
<div className="min-h-screen bg-white text-gray-900">
<div className="container mx-auto px-4 py-16 max-w-3xl">
<div className="prose max-w-none" dangerouslySetInnerHTML={{ __html: wrappedContent }} />
</div>
2025-02-14 11:05:58 +01:00
</div>
)
2025-02-15 12:22:29 +01:00
}