mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-08-25 13:51:15 +00:00
update footer
This commit is contained in:
@@ -7,37 +7,38 @@ import matter from "gray-matter"
|
||||
import dynamic from "next/dynamic"
|
||||
import React from "react"
|
||||
import parse from "html-react-parser"
|
||||
import Footer from "@/components/footer2"
|
||||
|
||||
const CopyableCode = dynamic(() => import("@/components/CopyableCode"), { ssr: false })
|
||||
|
||||
const guidesDirectory = path.join(process.cwd(), "..", "guides")
|
||||
|
||||
// 🔹 Encuentra todos los archivos Markdown dentro de `/guides`
|
||||
|
||||
function getMarkdownFiles() {
|
||||
return fs
|
||||
.readdirSync(guidesDirectory)
|
||||
.filter((file) => file.endsWith(".md"))
|
||||
.map((file) => ({
|
||||
slug: file.replace(/\.md$/, ""), // 🔹 Quitamos la extensión .md
|
||||
slug: file.replace(/\.md$/, ""),
|
||||
path: path.join(guidesDirectory, file),
|
||||
}))
|
||||
}
|
||||
|
||||
// 🔹 Obtiene el contenido de una guía específica
|
||||
|
||||
async function getGuideContent(slug: string) {
|
||||
try {
|
||||
const markdownFiles = getMarkdownFiles()
|
||||
const guideFile = markdownFiles.find((file) => file.slug === slug)
|
||||
|
||||
if (!guideFile) {
|
||||
console.error(`❌ No se encontró la guía: ${slug}`)
|
||||
return { content: "<p class='text-red-600'>Error: No se encontró la guía solicitada.</p>", metadata: null }
|
||||
console.error(`Guide not found.: ${slug}`)
|
||||
return { content: "<p class='text-red-600'>Error: Guide not found.</p>", metadata: null }
|
||||
}
|
||||
|
||||
const fileContents = fs.readFileSync(guideFile.path, "utf8")
|
||||
const { content, data } = matter(fileContents) // 🔹 Extrae metadata y contenido del `.md`
|
||||
const { content, data } = matter(fileContents)
|
||||
|
||||
// 🔹 Convertimos el Markdown a HTML con soporte para imágenes y tablas
|
||||
|
||||
const result = await remark()
|
||||
.use(gfm.default || gfm)
|
||||
.use(html)
|
||||
@@ -50,7 +51,7 @@ async function getGuideContent(slug: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// 🔹 Generamos rutas estáticas asegurando que Next.js las acepte
|
||||
|
||||
export async function generateStaticParams() {
|
||||
try {
|
||||
const markdownFiles = getMarkdownFiles()
|
||||
@@ -61,14 +62,14 @@ export async function generateStaticParams() {
|
||||
}
|
||||
}
|
||||
|
||||
// 🔹 Limpia las comillas invertidas en fragmentos de código en línea
|
||||
|
||||
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>`
|
||||
})
|
||||
}
|
||||
|
||||
// 🔹 Envuelve los bloques de código en `<CopyableCode />`
|
||||
|
||||
function wrapCodeBlocksWithCopyable(content: string) {
|
||||
return parse(content, {
|
||||
replace: (domNode: any) => {
|
||||
@@ -83,7 +84,7 @@ function wrapCodeBlocksWithCopyable(content: string) {
|
||||
})
|
||||
}
|
||||
|
||||
// 🔹 Página principal de cada guía
|
||||
|
||||
export default async function GuidePage({ params }: { params: { slug: string } }) {
|
||||
const { content, metadata } = await getGuideContent(params.slug)
|
||||
const cleanedInlineCode = cleanInlineCode(content)
|
||||
@@ -96,6 +97,7 @@ export default async function GuidePage({ params }: { params: { slug: string } }
|
||||
{metadata?.description && <p className="text-lg text-gray-700 mb-8">{metadata.description}</p>}
|
||||
<div className="prose max-w-none text-[16px]">{parsedContent}</div>
|
||||
</div>
|
||||
</footer2>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user