refactor: simplify documentation structure by removing multi-language i18n support and unused components
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { HomeLayout } from "fumadocs-ui/layouts/home";
|
||||
import { baseOptions } from "@/lib/layout.shared";
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode; params: Promise<{ lang: string }>}) {
|
||||
export default function Layout({ children }: LayoutProps<"/">) {
|
||||
return <HomeLayout {...baseOptions()}>{children}</HomeLayout>;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ export default function HomePage() {
|
||||
<h1 className="text-2xl font-bold mb-4">Hello World</h1>
|
||||
<p>
|
||||
You can open{" "}
|
||||
<Link href="/[lang]/docs" className="font-medium underline">
|
||||
<Link href="/docs" className="font-medium underline">
|
||||
/docs
|
||||
</Link>{" "}
|
||||
and see the documentation.
|
||||
@@ -1,38 +0,0 @@
|
||||
import { RootProvider } from "fumadocs-ui/provider/next";
|
||||
import "./global.css";
|
||||
import { Inter } from "next/font/google";
|
||||
import { defineI18nUI } from "fumadocs-ui/i18n";
|
||||
import { i18n } from "@/lib/i18n";
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const { provider } = defineI18nUI(i18n, {
|
||||
translations: {
|
||||
en: {
|
||||
displayName: "English",
|
||||
},
|
||||
fr: {
|
||||
displayName: "French",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default async function RootLayout({
|
||||
params,
|
||||
children,
|
||||
}: {
|
||||
params: Promise<{ lang: string }>;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const lang = (await params).lang;
|
||||
|
||||
return (
|
||||
<html lang={lang}>
|
||||
<body className={inter.className}>
|
||||
<RootProvider i18n={provider(lang)}>{children}</RootProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -2,8 +2,6 @@ import { source } from "@/lib/source";
|
||||
import { createFromSource } from "fumadocs-core/search/server";
|
||||
|
||||
export const { GET } = createFromSource(source, {
|
||||
localeMap: {
|
||||
fr: { language: 'french' },
|
||||
en: { language: 'english' },
|
||||
},
|
||||
// https://docs.orama.com/docs/orama-js/supported-languages
|
||||
language: "english",
|
||||
});
|
||||
|
||||
@@ -10,9 +10,9 @@ import { getMDXComponents } from "@/mdx-components";
|
||||
import type { Metadata } from "next";
|
||||
import { createRelativeLink } from "fumadocs-ui/mdx";
|
||||
|
||||
export default async function Page(props: { params: Promise<{ lang: string; slug?: string[]; }> }) {
|
||||
export default async function Page(props: PageProps<"/docs/[[...slug]]">) {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug, params.lang);
|
||||
const page = source.getPage(params.slug);
|
||||
if (!page) notFound();
|
||||
|
||||
const MDX = page.data.body;
|
||||
@@ -38,10 +38,10 @@ export async function generateStaticParams() {
|
||||
}
|
||||
|
||||
export async function generateMetadata(
|
||||
props: PageProps<"/docs/[[...slug]]"> & { params: Promise<{ lang: string; }> },
|
||||
props: PageProps<"/docs/[[...slug]]">,
|
||||
): Promise<Metadata> {
|
||||
const params = await props.params;
|
||||
const page = source.getPage(params.slug, params.lang);
|
||||
const page = source.getPage(params.slug);
|
||||
if (!page) notFound();
|
||||
|
||||
return {
|
||||
@@ -2,7 +2,7 @@ import { source } from "@/lib/source";
|
||||
import { DocsLayout } from "fumadocs-ui/layouts/docs";
|
||||
import { baseOptions } from "@/lib/layout.shared";
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
export default function Layout({ children }: LayoutProps<"/docs">) {
|
||||
return (
|
||||
<DocsLayout tree={source.getPageTree()} {...baseOptions()}>
|
||||
{children}
|
||||
17
documentation/src/app/layout.tsx
Normal file
17
documentation/src/app/layout.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { RootProvider } from "fumadocs-ui/provider/next";
|
||||
import "./global.css";
|
||||
import { Inter } from "next/font/google";
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export default function Layout({ children }: LayoutProps<"/">) {
|
||||
return (
|
||||
<html lang="en" className={inter.className} suppressHydrationWarning>
|
||||
<body className="flex flex-col min-h-screen">
|
||||
<RootProvider>{children}</RootProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export async function GET(
|
||||
<DefaultImage
|
||||
title={page.data.title}
|
||||
description={page.data.description}
|
||||
site="MemeGoat"
|
||||
site="My App"
|
||||
/>,
|
||||
{
|
||||
width: 1200,
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { use, useEffect, useId, useState } from 'react';
|
||||
import { useTheme } from 'next-themes';
|
||||
|
||||
export function Mermaid({ chart }: { chart: string }) {
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
if (!mounted) return;
|
||||
return <MermaidContent chart={chart} />;
|
||||
}
|
||||
|
||||
const cache = new Map<string, Promise<unknown>>();
|
||||
|
||||
function cachePromise<T>(key: string, setPromise: () => Promise<T>): Promise<T> {
|
||||
const cached = cache.get(key);
|
||||
if (cached) return cached as Promise<T>;
|
||||
|
||||
const promise = setPromise();
|
||||
cache.set(key, promise);
|
||||
return promise;
|
||||
}
|
||||
|
||||
function MermaidContent({ chart }: { chart: string }) {
|
||||
const id = useId();
|
||||
const { resolvedTheme } = useTheme();
|
||||
const { default: mermaid } = use(cachePromise('mermaid', () => import('mermaid')));
|
||||
|
||||
mermaid.initialize({
|
||||
startOnLoad: false,
|
||||
securityLevel: 'loose',
|
||||
fontFamily: 'inherit',
|
||||
themeCSS: 'margin: 1.5rem auto 0;',
|
||||
theme: resolvedTheme === 'dark' ? 'dark' : 'default',
|
||||
});
|
||||
|
||||
const { svg, bindFunctions } = use(
|
||||
cachePromise(`${chart}-${resolvedTheme}`, () => {
|
||||
return mermaid.render(id, chart.replaceAll('\\n', '\n'));
|
||||
}),
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={(container) => {
|
||||
if (container) bindFunctions?.(container);
|
||||
}}
|
||||
// biome-ignore lint/security/noDangerouslySetInnerHtml: correct usage.
|
||||
dangerouslySetInnerHTML={{ __html: svg }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { defineI18n } from "fumadocs-core/i18n";
|
||||
|
||||
export const i18n = defineI18n({
|
||||
defaultLanguage: "en",
|
||||
languages: ["en", "fr"],
|
||||
});
|
||||
@@ -1,11 +1,9 @@
|
||||
import type { BaseLayoutProps } from "fumadocs-ui/layouts/shared";
|
||||
import {i18n} from "@/lib/i18n";
|
||||
|
||||
export function baseOptions(): BaseLayoutProps {
|
||||
return {
|
||||
i18n,
|
||||
nav: {
|
||||
title: "MemeGoat",
|
||||
title: "My App",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { docs } from "fumadocs-mdx:collections/server";
|
||||
import { type InferPageType, loader } from "fumadocs-core/source";
|
||||
import { lucideIconsPlugin } from "fumadocs-core/source/lucide-icons";
|
||||
import {i18n} from "@/lib/i18n";
|
||||
|
||||
// See https://fumadocs.dev/docs/headless/source-api for more info
|
||||
export const source = loader({
|
||||
i18n,
|
||||
baseUrl: "/docs",
|
||||
source: docs.toFumadocsSource(),
|
||||
plugins: [lucideIconsPlugin()],
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
import defaultMdxComponents from "fumadocs-ui/mdx";
|
||||
import type { MDXComponents } from "mdx/types";
|
||||
import { Mermaid } from "@/components/mdx/mermaid";
|
||||
|
||||
export function getMDXComponents(components?: MDXComponents): MDXComponents {
|
||||
return {
|
||||
...defaultMdxComponents,
|
||||
...components,
|
||||
pre: ({ children, ...props }: any) => {
|
||||
if (
|
||||
children &&
|
||||
typeof children === "object" &&
|
||||
"type" in children &&
|
||||
(children as any).type === "code" &&
|
||||
(children as any).props.className === "language-mermaid"
|
||||
) {
|
||||
return <Mermaid chart={(children as any).props.children} />;
|
||||
}
|
||||
return <defaultMdxComponents.pre {...props}>{children}</defaultMdxComponents.pre>;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { createI18nMiddleware } from "fumadocs-core/i18n/middleware";
|
||||
import { i18n } from "@/lib/i18n";
|
||||
|
||||
export default createI18nMiddleware(i18n);
|
||||
|
||||
export const config = {
|
||||
// Matcher ignoring `/_next/` and `/api/`
|
||||
//TODO Adjust it to ignore static assets in `/public` folder
|
||||
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
|
||||
};
|
||||
Reference in New Issue
Block a user