mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-18 09:24:03 +00:00
New document (#5299)
* add new doc (#5175) Co-authored-by: dreamer6680 <146868355@qq.com> * Test docs (#5235) * fix: change the page of doc * chore: add new dependencies, update global styles/layout, optimize docs, add Feishu & GitHub icons, update API examples * fix: docs/index 404 not found * Update environment variable names, optimize styles, add new API routes, fix component styles, adjust documentation, and update GitHub and Feishu icons * update readme * feat: add a linkfastgpt compontent * feat: update new doc * fix:remove unuse page and redirect homepage to docs (#5288) * fix:remove some unuse doc * fix: redirect homepage to doc * git ignore * fix:navbar to index (#5295) * sidbar * fix: navtab unlight (#5298) * doc --------- Co-authored-by: dreamer6680 <1468683855@qq.com> Co-authored-by: dreamer6680 <146868355@qq.com>
This commit is contained in:
27
document/app/[lang]/(home)/layout.tsx
Normal file
27
document/app/[lang]/(home)/layout.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { HomeLayout } from 'fumadocs-ui/layouts/home';
|
||||
import LogoLight from '@/components/docs/logo';
|
||||
|
||||
export default async function Layout({
|
||||
params,
|
||||
children
|
||||
}: {
|
||||
params: Promise<{ lang: string }>;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const lang = (await params).lang;
|
||||
return (
|
||||
<HomeLayout
|
||||
nav={{
|
||||
title: (
|
||||
<div className="flex flex-row items-center gap-2 h-14">
|
||||
<LogoLight />
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
i18n
|
||||
>
|
||||
{children}
|
||||
</HomeLayout>
|
||||
);
|
||||
}
|
5
document/app/[lang]/(home)/page.tsx
Normal file
5
document/app/[lang]/(home)/page.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default function HomePage() {
|
||||
redirect(`/docs/introduction`);
|
||||
}
|
61
document/app/[lang]/docs/[[...slug]]/page.tsx
Normal file
61
document/app/[lang]/docs/[[...slug]]/page.tsx
Normal file
@@ -0,0 +1,61 @@
|
||||
import { source } from '@/lib/source';
|
||||
import { DocsPage, DocsBody, DocsDescription, DocsTitle } from 'fumadocs-ui/page';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { createRelativeLink } from 'fumadocs-ui/mdx';
|
||||
import { getMDXComponents } from '@/mdx-components';
|
||||
|
||||
export default async function Page({
|
||||
params
|
||||
}: {
|
||||
params: Promise<{ lang: string; slug?: string[] }>;
|
||||
}) {
|
||||
const { lang, slug } = await params;
|
||||
const page = source.getPage(slug, lang);
|
||||
if (!page || !page.data || !page.file) notFound();
|
||||
|
||||
const MDXContent = page.data.body;
|
||||
|
||||
return (
|
||||
<DocsPage
|
||||
toc={page.data.toc}
|
||||
full={page.data.full}
|
||||
tableOfContent={{
|
||||
style: 'clerk'
|
||||
}}
|
||||
editOnGithub={{
|
||||
owner: 'labring',
|
||||
repo: 'FastGPT',
|
||||
sha: 'main',
|
||||
path: `document/content/docs/${page.file.path}`
|
||||
}}
|
||||
lastUpdate={page.data.lastModified ? new Date(page.data.lastModified) : undefined}
|
||||
>
|
||||
<DocsTitle>{page.data.title}</DocsTitle>
|
||||
<DocsDescription>{page.data.description}</DocsDescription>
|
||||
<DocsBody>
|
||||
<MDXContent
|
||||
components={getMDXComponents({
|
||||
a: createRelativeLink(source, page)
|
||||
})}
|
||||
/>
|
||||
</DocsBody>
|
||||
</DocsPage>
|
||||
);
|
||||
}
|
||||
|
||||
export async function generateStaticParams() {
|
||||
return source.generateParams();
|
||||
}
|
||||
|
||||
export async function generateMetadata(props: {
|
||||
params: Promise<{ lang: string; slug?: string[] }>;
|
||||
}) {
|
||||
const { lang, slug } = await props.params;
|
||||
const page = source.getPage(slug, lang);
|
||||
if (!page || !page.data) notFound();
|
||||
|
||||
return {
|
||||
title: `${page.data.title} | FastGPT`,
|
||||
description: page.data.description
|
||||
};
|
||||
}
|
101
document/app/[lang]/docs/layout.tsx
Normal file
101
document/app/[lang]/docs/layout.tsx
Normal file
@@ -0,0 +1,101 @@
|
||||
import { type ReactNode } from 'react';
|
||||
import { source } from '@/lib/source';
|
||||
import { DocsLayout } from 'fumadocs-ui/layouts/notebook';
|
||||
import { baseOptions } from '@/app/layout.config';
|
||||
import { t } from '@/lib/i18n';
|
||||
import LogoLight from '@/components/docs/logo';
|
||||
import LogoDark from '@/components/docs/logoDark';
|
||||
import '@/app/global.css';
|
||||
import { CustomSidebarComponents } from '@/components/sideBar';
|
||||
import FeishuLogoLight from '@/components/docs/feishuLogoLIght';
|
||||
import FeishuLogoDark from '@/components/docs/feishuLogoDark';
|
||||
import GithubLogoLight from '@/components/docs/githubLogoLight';
|
||||
import GithubLogoDark from '@/components/docs/githubLogoDark';
|
||||
|
||||
export default async function Layout({
|
||||
params,
|
||||
children
|
||||
}: {
|
||||
params: Promise<{ lang: string }>;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const { lang } = await params;
|
||||
|
||||
const tab = [
|
||||
{
|
||||
title: t('common:introduction', lang),
|
||||
url: lang === 'zh-CN' ? '/docs/introduction' : '/en/docs/introduction'
|
||||
},
|
||||
{
|
||||
title: t('common:use-cases', lang),
|
||||
url: lang === 'zh-CN' ? '/docs/use-cases' : '/en/docs/use-cases'
|
||||
},
|
||||
{
|
||||
title: t('common:protocol', lang),
|
||||
url: lang === 'zh-CN' ? '/docs/protocol' : '/en/docs/protocol'
|
||||
}
|
||||
];
|
||||
|
||||
return (
|
||||
<DocsLayout
|
||||
{...baseOptions(lang)}
|
||||
nav={{
|
||||
title: (
|
||||
<div className="flex flex-row items-center gap-2 h-14 ml-10">
|
||||
<div className="block dark:hidden">
|
||||
<LogoLight className="w-48 h-auto" />
|
||||
</div>
|
||||
<div className="hidden dark:block">
|
||||
<LogoDark className="w-48 h-auto" />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
mode: 'top'
|
||||
}}
|
||||
links={[
|
||||
{
|
||||
type: 'icon',
|
||||
icon: (
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<div className="block dark:hidden">
|
||||
<FeishuLogoLight />
|
||||
</div>
|
||||
<div className="hidden dark:block">
|
||||
<FeishuLogoDark />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
url: 'https://oss.laf.run/otnvvf-imgs/fastgpt-feishu1.png',
|
||||
text: '飞书群'
|
||||
},
|
||||
{
|
||||
type: 'icon',
|
||||
icon: (
|
||||
<div className="flex flex-row items-center gap-2">
|
||||
<div className="block dark:hidden">
|
||||
<GithubLogoLight />
|
||||
</div>
|
||||
<div className="hidden dark:block">
|
||||
<GithubLogoDark />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
url: 'https://github.com/labring/FastGPT',
|
||||
text: 'github'
|
||||
}
|
||||
]}
|
||||
tree={source.pageTree[lang]}
|
||||
searchToggle={{
|
||||
enabled: true
|
||||
}}
|
||||
sidebar={{
|
||||
tabs: tab,
|
||||
collapsible: false,
|
||||
components: CustomSidebarComponents
|
||||
}}
|
||||
tabMode="navbar"
|
||||
>
|
||||
{children}
|
||||
</DocsLayout>
|
||||
);
|
||||
}
|
79
document/app/[lang]/layout.tsx
Normal file
79
document/app/[lang]/layout.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import '@/app/global.css';
|
||||
import { RootProvider } from 'fumadocs-ui/provider';
|
||||
import { Inter } from 'next/font/google';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { Translations } from 'fumadocs-ui/i18n';
|
||||
import CustomSearchDialog from '@/components/CustomSearchDialog';
|
||||
|
||||
const inter = Inter({
|
||||
subsets: ['latin']
|
||||
});
|
||||
|
||||
const zh_CN: Partial<Translations> = {
|
||||
search: '搜索',
|
||||
nextPage: '下一页',
|
||||
previousPage: '上一页',
|
||||
lastUpdate: '最后更新于',
|
||||
editOnGithub: '在 GitHub 上编辑',
|
||||
searchNoResult: '没有找到相关内容',
|
||||
toc: '本页导航',
|
||||
tocNoHeadings: '本页没有导航',
|
||||
chooseLanguage: '选择语言'
|
||||
};
|
||||
|
||||
const locales = [
|
||||
{
|
||||
name: 'English',
|
||||
locale: 'en'
|
||||
},
|
||||
{
|
||||
name: '简体中文',
|
||||
locale: 'zh-CN'
|
||||
}
|
||||
];
|
||||
|
||||
export default async function Layout({
|
||||
children,
|
||||
params
|
||||
}: {
|
||||
children: ReactNode;
|
||||
params: Promise<{ lang: string }>;
|
||||
}) {
|
||||
const { lang } = await params;
|
||||
|
||||
return (
|
||||
<html lang={lang} className={inter.className} suppressHydrationWarning>
|
||||
<body className="flex flex-col min-h-screen">
|
||||
<RootProvider
|
||||
i18n={{
|
||||
locale: lang,
|
||||
locales,
|
||||
translations: {
|
||||
'zh-CN': zh_CN,
|
||||
en: {
|
||||
search: 'Search',
|
||||
nextPage: 'Next Page',
|
||||
previousPage: 'Previous Page',
|
||||
lastUpdate: 'Last Updated',
|
||||
editOnGithub: 'Edit on GitHub',
|
||||
searchNoResult: 'No results found',
|
||||
toc: 'On this page',
|
||||
tocNoHeadings: 'No headings',
|
||||
chooseLanguage: 'Choose Language'
|
||||
}
|
||||
}[lang]
|
||||
}}
|
||||
search={{
|
||||
enabled: true,
|
||||
SearchDialog: CustomSearchDialog
|
||||
}}
|
||||
theme={{
|
||||
enabled: true
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</RootProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
56
document/app/[lang]/llms.txt/route.ts
Normal file
56
document/app/[lang]/llms.txt/route.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import * as fs from 'node:fs/promises';
|
||||
import fg from 'fast-glob';
|
||||
import matter from 'gray-matter';
|
||||
import { remark } from 'remark';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import remarkStringify from 'remark-stringify';
|
||||
import remarkMdx from 'remark-mdx';
|
||||
import { remarkInclude } from 'fumadocs-mdx/config';
|
||||
import { i18n } from '@/lib/i18n';
|
||||
|
||||
export const revalidate = false;
|
||||
|
||||
const processor = remark()
|
||||
.use(remarkMdx)
|
||||
// https://fumadocs.vercel.app/docs/mdx/include
|
||||
.use(remarkInclude)
|
||||
// gfm styles
|
||||
.use(remarkGfm)
|
||||
// .use(your remark plugins)
|
||||
.use(remarkStringify); // to string
|
||||
|
||||
export async function GET() {
|
||||
// all scanned content
|
||||
// Select files based on the default language
|
||||
const defaultLanguage = i18n.defaultLanguage;
|
||||
let globPattern;
|
||||
|
||||
if (defaultLanguage === 'zh-CN') {
|
||||
// For Chinese, select *.mdx files
|
||||
globPattern = ['./content/docs/**/*.mdx'];
|
||||
} else {
|
||||
// For other languages (default English), select *.en.mdx files that don't have .mdx. in their path
|
||||
globPattern = ['./content/docs/**/*.en.mdx'];
|
||||
}
|
||||
|
||||
const files = await fg(globPattern);
|
||||
|
||||
const scan = files.map(async (file: string) => {
|
||||
const fileContent = await fs.readFile(file);
|
||||
const { content, data } = matter(fileContent.toString());
|
||||
|
||||
const processed = await processor.process({
|
||||
path: file,
|
||||
value: content
|
||||
});
|
||||
|
||||
return `file: ${file}
|
||||
meta: ${JSON.stringify(data, null, 2)}
|
||||
|
||||
${processed}`;
|
||||
});
|
||||
|
||||
const scanned = await Promise.all(scan);
|
||||
|
||||
return new Response(scanned.join('\n\n'));
|
||||
}
|
Reference in New Issue
Block a user