ProxMenux/web/app/guides/page.tsx

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-02-15 23:45:44 +01:00
import type React from "react"
2025-02-15 17:39:01 +01:00
import fs from "fs"
import path from "path"
import matter from "gray-matter"
2025-02-13 17:28:49 +01:00
import Link from "next/link"
2025-02-15 23:41:32 +01:00
import Footer from "@/components/footer"
2025-02-13 17:28:49 +01:00
2025-02-15 17:39:01 +01:00
const guidesDirectory = path.join(process.cwd(), "..", "guides")
2025-02-13 17:28:49 +01:00
interface Guide {
title: string
description: string
slug: string
}
2025-02-15 17:39:01 +01:00
function getGuides(): Guide[] {
let guides: Guide[] = []
function findGuides(dir: string, basePath = "") {
fs.readdirSync(dir, { withFileTypes: true }).forEach((entry) => {
const fullPath = path.join(dir, entry.name)
const relativePath = path.join(basePath, entry.name)
if (entry.isDirectory()) {
findGuides(fullPath, relativePath)
} else if (entry.isFile() && entry.name.endsWith(".md")) {
const slug = relativePath.replace(/\.md$/, "")
// 🔹 Extraer metadatos usando gray-matter
const fileContents = fs.readFileSync(fullPath, "utf8")
const { data } = matter(fileContents)
guides.push({
title: data.title || slug.replace(/_/g, " "),
description: data.description || "No description available.",
slug,
})
}
})
}
findGuides(guidesDirectory)
return guides
}
2025-02-13 17:28:49 +01:00
export default function GuidesPage() {
2025-02-15 17:39:01 +01:00
const guides = getGuides()
2025-02-13 17:28:49 +01:00
return (
2025-02-16 00:06:51 +01:00
<div className="min-h-screen bg-gradient-to-b from-gray-900 to-gray-800 text-white pt-16 flex flex-col">
2025-02-15 23:26:41 +01:00
<div className="container mx-auto px-4 py-16">
<h1 className="text-4xl font-bold mb-8">ProxMenux Guides</h1>
<p className="text-xl mb-8">Complementary guides to make the most of your Proxmox VE.</p>
<div className="grid md:grid-cols-2 gap-6">
{guides.map((guide) => (
<Link
key={guide.slug}
href={`/guides/${guide.slug}`}
2025-02-15 23:41:32 +01:00
className="block p-6 bg-white rounded-lg shadow-md hover:shadow-lg transition-shadow"
2025-02-15 23:26:41 +01:00
>
2025-02-15 23:41:32 +01:00
<h2 className="text-2xl font-semibold mb-2 text-gray-900">{guide.title}</h2>
<p className="text-gray-600">{guide.description}</p>
2025-02-15 23:26:41 +01:00
</Link>
))}
</div>
2025-02-13 17:28:49 +01:00
</div>
2025-02-15 23:53:08 +01:00
<Footer />
2025-02-13 17:28:49 +01:00
</div>
)
}