2026-08-19 17:40:14 +07:00
|
|
|
import Link from "next/link";
|
|
|
|
|
import { notFound } from "next/navigation";
|
2026-08-20 13:08:27 +07:00
|
|
|
import { cookies } from "next/headers";
|
|
|
|
|
import { getDocument, getRelated, listRevisions } from "@mcpedia/core";
|
|
|
|
|
import { WEBHOOK_SECRET } from "@mcpedia/config";
|
2026-08-19 17:40:14 +07:00
|
|
|
import Markdown from "@/components/Markdown";
|
2026-08-20 13:08:27 +07:00
|
|
|
import DocForm from "@/components/DocForm";
|
2026-08-20 13:21:53 +07:00
|
|
|
import TOC from "@/components/TOC";
|
2026-08-19 17:40:14 +07:00
|
|
|
|
2026-08-20 16:57:30 +07:00
|
|
|
// Render at request time (content in Postgres, not available at build time).
|
2026-08-19 22:56:01 +07:00
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
2026-08-20 13:08:27 +07:00
|
|
|
interface DocPageProps {
|
2026-08-19 17:40:14 +07:00
|
|
|
params: Promise<{ section: string; slug: string[] }>;
|
2026-08-20 13:08:27 +07:00
|
|
|
searchParams: Promise<{ edit?: string }>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function DocPage({ params, searchParams }: DocPageProps) {
|
2026-08-19 17:40:14 +07:00
|
|
|
const { section, slug } = await params;
|
2026-08-20 13:08:27 +07:00
|
|
|
const { edit } = await searchParams;
|
2026-08-19 17:40:14 +07:00
|
|
|
const fullSlug = `${section}/${slug.join("/")}`;
|
|
|
|
|
const doc = await getDocument(fullSlug);
|
|
|
|
|
if (!doc) notFound();
|
|
|
|
|
|
2026-08-20 13:08:27 +07:00
|
|
|
const cookieStore = await cookies();
|
|
|
|
|
const canEdit = cookieStore.get("mcpedia_admin")?.value != null;
|
|
|
|
|
|
2026-08-20 16:57:30 +07:00
|
|
|
// Edit mode: inline form
|
2026-08-20 13:08:27 +07:00
|
|
|
if (edit === "1" && canEdit) {
|
|
|
|
|
return (
|
2026-08-20 16:57:30 +07:00
|
|
|
<div>
|
|
|
|
|
<Link
|
|
|
|
|
href={`/${doc.slug}`}
|
|
|
|
|
className="text-xs text-[#8a8f98] hover:text-[#d0d6e0] mb-4 inline-block"
|
|
|
|
|
>
|
|
|
|
|
← Back to {doc.title}
|
|
|
|
|
</Link>
|
|
|
|
|
<h1 className="text-2xl font-light text-[#f7f8f8] mb-6">
|
|
|
|
|
Edit: {doc.title}
|
|
|
|
|
</h1>
|
2026-08-20 13:08:27 +07:00
|
|
|
<DocForm
|
|
|
|
|
mode="edit"
|
|
|
|
|
slug={fullSlug}
|
|
|
|
|
secret={WEBHOOK_SECRET}
|
|
|
|
|
initial={{
|
|
|
|
|
title: doc.title,
|
|
|
|
|
body: doc.body,
|
|
|
|
|
section: doc.section,
|
|
|
|
|
type: doc.type,
|
|
|
|
|
status: doc.status,
|
|
|
|
|
tags: doc.tags,
|
|
|
|
|
author: doc.author,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-19 17:40:14 +07:00
|
|
|
const related = await getRelated(fullSlug, 5);
|
2026-08-19 21:54:54 +07:00
|
|
|
const revisions = await listRevisions(fullSlug, 10);
|
2026-08-19 17:40:14 +07:00
|
|
|
|
|
|
|
|
return (
|
2026-08-20 16:57:30 +07:00
|
|
|
<article>
|
|
|
|
|
<div className="mb-2 flex items-center gap-2 text-xs text-[#62666d]">
|
|
|
|
|
<Link
|
|
|
|
|
href="/"
|
|
|
|
|
className="hover:text-[#d0d6e0] transition-colors"
|
|
|
|
|
>
|
|
|
|
|
MCPedia
|
|
|
|
|
</Link>
|
|
|
|
|
<span>/</span>
|
|
|
|
|
<Link
|
|
|
|
|
href="/docs"
|
|
|
|
|
className="hover:text-[#d0d6e0] transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Docs
|
2026-08-19 17:40:14 +07:00
|
|
|
</Link>
|
2026-08-20 13:08:27 +07:00
|
|
|
{canEdit && (
|
2026-08-20 16:57:30 +07:00
|
|
|
<>
|
|
|
|
|
<span>/</span>
|
|
|
|
|
<Link
|
|
|
|
|
href={`/${doc.slug}?edit=1`}
|
|
|
|
|
className="hover:text-[#d0d6e0] text-[#8a8f98] hover:text-[#5e6ad2] transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Edit
|
|
|
|
|
</Link>
|
|
|
|
|
</>
|
2026-08-20 13:08:27 +07:00
|
|
|
)}
|
2026-08-19 17:40:14 +07:00
|
|
|
</div>
|
|
|
|
|
|
2026-08-20 16:57:30 +07:00
|
|
|
<h1 className="text-3xl font-light text-[#f7f8f8] mb-2">{doc.title}</h1>
|
2026-08-20 13:21:53 +07:00
|
|
|
|
2026-08-20 16:57:30 +07:00
|
|
|
<div className="flex items-center gap-3 text-xs text-[#62666d] mb-6">
|
|
|
|
|
<span>{doc.author || "unknown"}</span>
|
|
|
|
|
<span>•</span>
|
|
|
|
|
<span>{new Date(doc.updatedAt).toLocaleDateString()}</span>
|
|
|
|
|
{doc.tags.map((t) => (
|
|
|
|
|
<span
|
|
|
|
|
key={t}
|
|
|
|
|
className="px-2 py-0.5 bg-[#191a1b] border border-[#23252a] rounded text-[#d0d6e0]"
|
|
|
|
|
>
|
|
|
|
|
#{t}
|
|
|
|
|
</span>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="mb-8">
|
|
|
|
|
<TOC source={doc.body} />
|
|
|
|
|
<Markdown source={doc.body} />
|
|
|
|
|
</div>
|
2026-08-19 17:40:14 +07:00
|
|
|
|
|
|
|
|
{related.length > 0 && (
|
2026-08-20 16:57:30 +07:00
|
|
|
<aside className="mt-12 pt-6 border-t border-[#1f2022]">
|
|
|
|
|
<h2 className="text-sm font-medium text-[#d0d6e0] uppercase mb-3">
|
|
|
|
|
Related
|
|
|
|
|
</h2>
|
|
|
|
|
<ul className="space-y-2">
|
2026-08-19 17:40:14 +07:00
|
|
|
{related.map((r) => (
|
|
|
|
|
<li key={r.slug}>
|
2026-08-20 16:57:30 +07:00
|
|
|
<Link
|
|
|
|
|
href={`/${r.slug}`}
|
|
|
|
|
className="text-[#d0d6e0] hover:text-[#f7f8f8] transition-colors"
|
|
|
|
|
>
|
2026-08-19 17:40:14 +07:00
|
|
|
{r.title}
|
|
|
|
|
</Link>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</aside>
|
|
|
|
|
)}
|
2026-08-19 21:54:54 +07:00
|
|
|
|
|
|
|
|
{revisions.length > 0 && (
|
2026-08-20 16:57:30 +07:00
|
|
|
<aside className="mt-12 pt-6 border-t border-[#1f2022]">
|
|
|
|
|
<h2 className="text-sm font-medium text-[#d0d6e0] uppercase mb-3">
|
|
|
|
|
History
|
|
|
|
|
</h2>
|
|
|
|
|
<ul className="text-sm">
|
2026-08-19 21:54:54 +07:00
|
|
|
{revisions.map((rev) => (
|
|
|
|
|
<li
|
|
|
|
|
key={rev.id}
|
2026-08-20 16:57:30 +07:00
|
|
|
className="flex items-center justify-between gap-3 py-1.5 border-b border-[#141516]"
|
2026-08-19 21:54:54 +07:00
|
|
|
>
|
2026-08-20 16:57:30 +07:00
|
|
|
<span className="text-[#8a8f98]">
|
2026-08-19 21:54:54 +07:00
|
|
|
#{rev.revisionNo} · {rev.reason} ·{" "}
|
2026-08-20 16:57:30 +07:00
|
|
|
{new Date(rev.createdAt).toLocaleString()}
|
2026-08-19 21:54:54 +07:00
|
|
|
</span>
|
2026-08-20 13:08:27 +07:00
|
|
|
<form action="/api/revisions/restore" method="post">
|
2026-08-19 21:54:54 +07:00
|
|
|
<input type="hidden" name="id" value={rev.id} />
|
|
|
|
|
<button
|
|
|
|
|
type="submit"
|
2026-08-20 16:57:30 +07:00
|
|
|
className="text-xs text-[#d0d6e0] hover:text-[#5e6ad2] px-2 py-0.5 rounded border border-[#1f2022] hover:border-[#5e6ad2] transition-colors"
|
2026-08-19 21:54:54 +07:00
|
|
|
>
|
|
|
|
|
Restore
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</aside>
|
|
|
|
|
)}
|
2026-08-19 17:40:14 +07:00
|
|
|
</article>
|
|
|
|
|
);
|
|
|
|
|
}
|