import Link from "next/link"; import { notFound } from "next/navigation"; import { Header, Footer } from "@/components/Shell"; import guides from "@/shared/player-docs.json"; import styles from "./page.module.css"; export const metadata = { title: "Player docs" }; function inline(text: string) { return text .split(/(\*\*[^*]+\*\*|\[[^\]]+\]\(https:\/\/[^)]+\))/g) .map((part, index) => { if (part.startsWith("**")) return {part.slice(2, -2)}; const link = part.match(/^\[([^\]]+)\]\((https:\/\/[^)]+)\)$/); return link ? ( {link[1]} ) : ( part ); }); } function content(markdown: string) { return markdown.split(/\n\s*\n/).map((block, index) => { const heading = block.match(/^(#{1,3}) (.+)$/); if (heading) { const text = inline(heading[2]); return heading[1].length === 1 ? (

{text}

) : heading[1].length === 2 ? (

{text}

) : (

{text}

); } const image = block.match(/^!\[([^\]]*)\]\((https:\/\/[^)]+)\)$/); if (image) return (
{image[1]}
); if (block.startsWith("> ")) return (
{inline(block.replace(/^> /gm, ""))}
); const lines = block.split("\n"); if (lines.every((line) => /^[-*] /.test(line))) return ( ); if (lines.every((line) => /^\d+\. /.test(line))) return (
    {lines.map((line, i) => (
  1. {inline(line.replace(/^\d+\. /, ""))}
  2. ))}
); return

{inline(block)}

; }); } export default async function Docs({ searchParams, }: { searchParams: Promise<{ page?: string }>; }) { const { page = "welcome" } = await searchParams; const guide = guides.find((item) => item.slug === page); if (!guide) notFound(); const index = guides.indexOf(guide); return ( <>
{content(guide.markdown)}
{index > 0 && ( ← {guides[index - 1].title} )} {index < guides.length - 1 && ( {guides[index + 1].title} → )}