|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import React, { useEffect } from "react"; |
| 4 | +import ReactMarkdown from "react-markdown"; |
| 5 | +import rehypeRaw from "rehype-raw"; |
| 6 | +import rehypeHighlight from "rehype-highlight"; |
| 7 | +import { |
| 8 | + DynamicLayout, |
| 9 | + MobileSidebar, |
| 10 | + NavigationButton, |
| 11 | + Sidebar, |
| 12 | + TOC, |
| 13 | +} from "@/components/docs"; |
| 14 | +import { generateTOC } from "@/lib/generateTOC"; |
| 15 | + |
| 16 | +interface GuidePageProps { |
| 17 | + params: { |
| 18 | + lang: string; |
| 19 | + group: string; |
| 20 | + slug: string; |
| 21 | + }; |
| 22 | + content: string; |
| 23 | + title: string; |
| 24 | + prevDocument: any; |
| 25 | + nextDocument: any; |
| 26 | + allDocuments: any[]; |
| 27 | +} |
| 28 | + |
| 29 | +export default function GuidePage({ |
| 30 | + params, |
| 31 | + content, |
| 32 | + title, |
| 33 | + prevDocument, |
| 34 | + nextDocument, |
| 35 | + allDocuments, |
| 36 | +}: GuidePageProps) { |
| 37 | + const { lang, group, slug } = params; |
| 38 | + const tocItems = generateTOC(content); |
| 39 | + |
| 40 | + useEffect(() => { |
| 41 | + const headings = document.querySelectorAll("h1, h2, h3, h4, h5, h6"); |
| 42 | + headings.forEach((heading) => { |
| 43 | + heading.id = |
| 44 | + heading.textContent?.toLowerCase().replace(/\s+/g, "-") ?? ""; |
| 45 | + }); |
| 46 | + }, [content]); |
| 47 | + |
| 48 | + return ( |
| 49 | + <DynamicLayout |
| 50 | + sidebar={ |
| 51 | + <Sidebar |
| 52 | + documents={allDocuments} |
| 53 | + currentSlug={slug} |
| 54 | + currentGroup={group} |
| 55 | + lang={lang} |
| 56 | + /> |
| 57 | + } |
| 58 | + mobileSidebar={ |
| 59 | + <MobileSidebar |
| 60 | + documents={allDocuments} |
| 61 | + currentSlug={slug} |
| 62 | + currentGroup={group} |
| 63 | + lang={lang} |
| 64 | + /> |
| 65 | + } |
| 66 | + toc={<TOC items={tocItems} />} |
| 67 | + > |
| 68 | + <div className="p-4 sm:p-8 md:p-12 bg-white dark:bg-black rounded-sm"> |
| 69 | + <p className="text-lg sm:text-xl font-bold mb-4 dark:text-white"> |
| 70 | + {group} > {title} |
| 71 | + </p> |
| 72 | + <ReactMarkdown |
| 73 | + className="prose prose-sm sm:prose lg:prose-lg dark:prose-invert prose-headings:dark:text-white prose-p:dark:text-gray-300 prose-strong:dark:text-white prose-code:dark:text-white prose-ul:dark:text-gray-300 prose-ol:dark:text-gray-300" |
| 74 | + rehypePlugins={[rehypeRaw, rehypeHighlight]} |
| 75 | + > |
| 76 | + {content} |
| 77 | + </ReactMarkdown> |
| 78 | + </div> |
| 79 | + <div className="mt-8 mb-4 flex justify-between gap-4"> |
| 80 | + <div className="flex-1"> |
| 81 | + {prevDocument && ( |
| 82 | + <NavigationButton |
| 83 | + document={prevDocument} |
| 84 | + lang={lang} |
| 85 | + direction="prev" |
| 86 | + /> |
| 87 | + )} |
| 88 | + </div> |
| 89 | + <div className="flex-1"> |
| 90 | + {nextDocument && ( |
| 91 | + <NavigationButton |
| 92 | + document={nextDocument} |
| 93 | + lang={lang} |
| 94 | + direction="next" |
| 95 | + /> |
| 96 | + )} |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </DynamicLayout> |
| 100 | + ); |
| 101 | +} |
0 commit comments