From 864911af20df1b2285eba7420ee8d7324df5fcce Mon Sep 17 00:00:00 2001 From: asepharyana Date: Sat, 22 Aug 2026 11:55:58 +0700 Subject: [PATCH] feat(export): enhance export routing to support /[section]/export, /[section]/[slug]/export, and dynamic route rendering --- apps/web/app/[section]/[...slug]/page.tsx | 25 +++++++++++++++++++---- apps/web/app/[section]/page.tsx | 4 ++-- apps/web/app/components/DocActions.tsx | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/web/app/[section]/[...slug]/page.tsx b/apps/web/app/[section]/[...slug]/page.tsx index 18503dc..87de718 100644 --- a/apps/web/app/[section]/[...slug]/page.tsx +++ b/apps/web/app/[section]/[...slug]/page.tsx @@ -1,12 +1,13 @@ import Link from "next/link"; import { notFound } from "next/navigation"; import { cookies } from "next/headers"; -import { getDocument, getRelated, listRevisions, listDocuments } from "@mcpedia/core"; +import { getDocument, getRelated, listRevisions, listDocuments, getExportDocuments } from "@mcpedia/core"; import { WEBHOOK_SECRET } from "@mcpedia/config"; import Markdown from "@/components/Markdown"; import DocForm from "@/components/DocForm"; import TOC from "@/components/TOC"; import DocActions from "@/components/DocActions"; +import PdfExportView from "@/components/PdfExportView"; import { classifyPath, extractFoldersForSection } from "@mcpedia/core"; import { getSectionMeta } from "@mcpedia/config"; import type { DocumentMeta } from "@mcpedia/core"; @@ -15,7 +16,7 @@ export const dynamic = "force-dynamic"; interface DocPageProps { params: Promise<{ section: string; slug: string[] }>; - searchParams: Promise<{ edit?: string }>; + searchParams: Promise<{ edit?: string; path?: string; sort?: string }>; } function getSectionInfo(section: string) { @@ -191,7 +192,7 @@ function FolderIndexPage({ {immediateDocs.length + folders.length} item{folders.length + immediateDocs.length !== 1 ? "s" : ""} @@ -288,7 +289,23 @@ function FolderIndexPage({ export default async function DocPage({ params, searchParams }: DocPageProps) { const { section, slug } = await params; - const { edit } = await searchParams; + const searchParamsObj = await searchParams; + const { edit, path: queryPath, sort } = searchParamsObj; + + // Handle direct export views: /[section]/export, /[section]/[...folder]/export, or /export/pdf + if (section === "export" || (slug && slug[slug.length - 1] === "export")) { + const isTrailingExport = slug && slug[slug.length - 1] === "export"; + const targetSlug = isTrailingExport ? slug.slice(0, -1) : slug; + const targetPath = queryPath || (targetSlug.length > 0 ? `${section}/${targetSlug.join("/")}` : section); + const exportData = await getExportDocuments({ + path: targetPath === "export" ? queryPath : targetPath, + section: targetPath === section ? section : undefined, + sortBy: (sort as any) || "category_points", + }); + const backHref = targetPath && targetPath !== "export" ? `/${targetPath}` : section !== "export" ? `/${section}` : "/"; + return ; + } + const fullSlug = `${section}/${slug.join("/")}`; const allDocs = await listDocuments(); diff --git a/apps/web/app/[section]/page.tsx b/apps/web/app/[section]/page.tsx index ccec5fd..4867572 100644 --- a/apps/web/app/[section]/page.tsx +++ b/apps/web/app/[section]/page.tsx @@ -157,8 +157,8 @@ export default async function SectionIndexPage({ {sectionDocs.length > 0 && ( 📄 diff --git a/apps/web/app/components/DocActions.tsx b/apps/web/app/components/DocActions.tsx index 5bf5b8f..d9f0399 100644 --- a/apps/web/app/components/DocActions.tsx +++ b/apps/web/app/components/DocActions.tsx @@ -77,7 +77,7 @@ export default function DocActions({ slug, body, canEdit }: DocActionsProps) { {/* Export PDF */}