mirror of https://github.com/Lapikud/tipilan
parent
018c7c53e5
commit
deb07df397
9 changed files with 378 additions and 328 deletions
@ -1,49 +1,103 @@ |
|||||||
|
import { notFound } from "next/navigation"; |
||||||
|
import ReactMarkdown, { Components } from "react-markdown"; |
||||||
import { vipnagorgialla } from "@/components/Vipnagorgialla"; |
import { vipnagorgialla } from "@/components/Vipnagorgialla"; |
||||||
import path from "node:path"; |
|
||||||
import fs from "node:fs/promises"; |
|
||||||
import ReactMarkdown from "react-markdown"; |
|
||||||
import SectionDivider from "@/components/SectionDivider"; |
import SectionDivider from "@/components/SectionDivider"; |
||||||
|
|
||||||
type Props = { |
// Map of valid slugs to their corresponding file paths and titles
|
||||||
|
const rulesMap = { |
||||||
|
lol: { |
||||||
|
filePath: "src/data/rules/lol.md", |
||||||
|
title: "LOL Reeglid", |
||||||
|
}, |
||||||
|
cs2: { |
||||||
|
filePath: "src/data/rules/cs2.md", |
||||||
|
title: "CS2 Reeglid", |
||||||
|
}, |
||||||
|
} as const; |
||||||
|
|
||||||
|
type RuleSlug = keyof typeof rulesMap; |
||||||
|
|
||||||
|
interface PageProps { |
||||||
params: Promise<{ slug: string }>; |
params: Promise<{ slug: string }>; |
||||||
}; |
} |
||||||
|
|
||||||
export default async function RulePage({params}: Props) { |
async function getRuleContent(slug: string) { |
||||||
const {slug} = await params; |
if (!Object.keys(rulesMap).includes(slug)) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
const filePath = path.join(process.cwd(), "src/data/rules", `${slug}.md`); |
const ruleConfig = rulesMap[slug as RuleSlug]; |
||||||
let file: string; |
|
||||||
|
|
||||||
try { |
try { |
||||||
file = await fs.readFile(filePath, "utf8"); |
const file = Bun.file(ruleConfig.filePath); |
||||||
} catch { |
const content = await file.text(); |
||||||
file = `# ${slug.toUpperCase()} REEGLID\n\nSisu hetkel puudub.`; |
return { |
||||||
|
content, |
||||||
|
title: ruleConfig.title, |
||||||
|
}; |
||||||
|
} catch (error) { |
||||||
|
console.error(`Error reading rule file for slug ${slug}:`, error); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
export default async function RulePage({ params }: PageProps) { |
||||||
|
const { slug } = await params; |
||||||
|
const ruleData = await getRuleContent(slug); |
||||||
|
|
||||||
|
if (!ruleData) { |
||||||
|
notFound(); |
||||||
} |
} |
||||||
|
|
||||||
const data = {title: undefined as string | undefined}; |
const headingStyle = `text-5xl sm:text-6xl ${vipnagorgialla.className} font-bold uppercase italic text-[#2A2C3F] dark:text-[#EEE5E5]`; |
||||||
|
|
||||||
return ( |
return ( |
||||||
<> |
<div> |
||||||
<div className="mb-16"> |
<div className="flex flex-col min-h-[90vh] m-6 mt-16 md:m-16"> |
||||||
<h1 |
<h1 className={`${headingStyle} mt-8 md:mt-16 mb-4`}> |
||||||
className={`not-prose ${vipnagorgialla.className} font-bold italic uppercase text-[64px] leading-[96px] tracking-[-0.02em] text-[#2A2C3F] dark:text-[#EEE5E5] mx-auto mt-16 mb-6 px-8`} |
{ruleData.title} |
||||||
> |
|
||||||
{data.title || `${slug.toUpperCase()} REEGLID`} |
|
||||||
</h1> |
</h1> |
||||||
|
|
||||||
<div |
<div className="prose prose-lg dark:prose-invert max-w-none"> |
||||||
className={`mx-auto px-8 font-worksans
|
<ReactMarkdown |
||||||
[&_ol]:ml-6 |
components={ |
||||||
[&_ol_ol]:ml-10 |
{ |
||||||
[&_ol_ol_ol]:ml-14 |
h1: (props) => ( |
||||||
[&_h2]:font-bold |
<h1 className="text-3xl md:text-4xl font-bold my-4"> |
||||||
`}
|
{props.children} |
||||||
|
</h1> |
||||||
|
), |
||||||
|
h2: (props) => ( |
||||||
|
<h2 className="text-2xl md:text-3xl font-semibold my-3"> |
||||||
|
{props.children} |
||||||
|
</h2> |
||||||
|
), |
||||||
|
ol: (props) => ( |
||||||
|
<ol className="list-none ml-6 md:text-xl"> |
||||||
|
{props.children} |
||||||
|
</ol> |
||||||
|
), |
||||||
|
ul: (props) => ( |
||||||
|
<ul className="list-disc ml-6 md:text-xl"> |
||||||
|
{props.children} |
||||||
|
</ul> |
||||||
|
), |
||||||
|
p: (props) => <p className="md:text-xl">{props.children}</p>, |
||||||
|
} as Components |
||||||
|
} |
||||||
> |
> |
||||||
<ReactMarkdown>{file}</ReactMarkdown> |
{ruleData.content} |
||||||
|
</ReactMarkdown> |
||||||
</div> |
</div> |
||||||
</div> |
</div> |
||||||
|
|
||||||
<SectionDivider /> |
<SectionDivider /> |
||||||
</> |
</div> |
||||||
); |
); |
||||||
} |
} |
||||||
|
|
||||||
|
export async function generateStaticParams() { |
||||||
|
return Object.keys(rulesMap).map((slug) => ({ |
||||||
|
slug, |
||||||
|
})); |
||||||
|
} |
||||||
|
|||||||
@ -0,0 +1,5 @@ |
|||||||
|
## Tulekul |
||||||
|
|
||||||
|
CS2 turniiri reeglid on hetkel ettevalmistamisel ja avaldatakse peagi. |
||||||
|
|
||||||
|
Jälgige meie discordi! |
||||||
Loading…
Reference in new issue