Skip to content

Test docs #5235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions document/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
GITHUB_TOKEN=
NEXT_PUBLIC_SEARCH_APPKEY=
NEXT_PUBLIC_SEARCH_APPID=
GITHUB_REPO=
GITHUB_OWNER=
NEXT_PUBLIC_DOMAIN=
1,715 changes: 1,080 additions & 635 deletions document/.source/index.ts

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions document/.source/source.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// source.config.ts
import {
defineConfig,
defineDocs,
frontmatterSchema,
metaSchema
} from "fumadocs-mdx/config";
import { defineConfig, defineDocs, frontmatterSchema, metaSchema } from "fumadocs-mdx/config";
var docs = defineDocs({
docs: {
schema: frontmatterSchema
Expand Down
5 changes: 5 additions & 0 deletions document/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
ENV NEXT_PUBLIC_OPEN_SOURCE_URL=$NEXT_PUBLIC_OPEN_SOURCE_URL
ENV NEXT_PUBLIC_DEFAULT_LOCALE=$NEXT_PUBLIC_DEFAULT_LOCALE
ENV NEXT_TELEMETRY_DISABLED=1
ENV GITHUB_TOKEN=
ENV NEXT_PUBLIC_SEARCH_APPKEY=
ENV NEXT_PUBLIC_SEARCH_APPID=
ENV GITHUB_REPO=
ENV GITHUB_OWNER=

COPY . .
RUN npm install && npm run build
Expand Down
105 changes: 78 additions & 27 deletions document/README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,96 @@
# fast

This is a Next.js application generated with
[Create Fumadocs](https://github.com/fuma-nama/fumadocs).
这是FastGPT的官方文档,采用fumadoc框架。

Run development server:
# 获取搜索应用

点击[Algolia](https://dashboard.algolia.com/account/overview),进行注册账号,注册成功后需要点击页面的搜索,然后查看应用,默认会有一个应用。

![](./public/readme/algolia.png)

拥有应用后点击个人头像,点击设置,点击`API Keys`查看自己的应用id和key。

![](./public/readme/algolia2.png)

页面中的`Application ID`和`Search API Key`就是环境变量对应的`NEXT_PUBLIC_SEARCH_APPID`和`NEXT_PUBLIC_SEARCH_APPKEY`

![](./public/readme/algolia3.png)

# 运行项目

要运行文档,首先需要进行环境变量配置,在文档的根目录下创建`.env.local`文件,填写以下环境变量:

```bash
GITHUB_TOKEN = #这是github申请的token,`https://github.com/settings/personal-access-tokens`建议创建token时,采用只有选择的库可以使用token,这样更安全
NEXT_PUBLIC_SEARCH_APPKEY = #这是上面获取的搜索key
NEXT_PUBLIC_SEARCH_APPID = #这是上面的搜索id
GITHUB_REPO = #fork的仓库名
GITHUB_OWNER = #你的github名
NEXT_PUBLIC_DOMAIN = #要跳转的FastGPT项目的域名,默认海外版
```

你可以在FastGPT项目根目录下执行以下命令来运行文档。

```bash
npm install #只能npm install,不能pnpm
npm run dev
# or
pnpm dev
# or
yarn dev
```
项目会默认跑在`http:localhost:3000`端口

Open http://localhost:3000 with your browser to see the result.
# 书写文档

## Explore
文档采用`mdx`格式,大体和`md`一致,但是现在文档的元数据只支持`title` `description`和`icon`三个字段,参考以下示例代码:

In the project, you can see:
```bash
---
title: FastGPT 文档
description: FastGPT 官方文档
icon: menu #icon采用`lucide-react`第三方库。
---

- `lib/source.ts`: Code for content source adapter, [`loader()`](https://fumadocs.dev/docs/headless/source-api) provides the interface to access your content.
- `app/layout.config.tsx`: Shared options for layouts, optional but preferred to keep.
import { Alert } from '@/components/docs/Alert'; #高亮块组件

| Route | Description |
| ------------------------- | ------------------------------------------------------ |
| `app/(home)` | The route group for your landing page and other pages. |
| `app/docs` | The documentation layout and pages. |
| `app/api/search/route.ts` | The Route Handler for search. |
<Alert icon="🤖" context="success">
快速开始体验
- 海外版:[https://fastgpt.io](https://fastgpt.io)
- 国内版:[https://fastgpt.cn](https://fastgpt.cn)
</Alert>

import {Redirect} from '@/components/docs/Redirect' #重定向组件,如果你希望用户点击这个文件跳转到别的文件的话,详情参考 `FAQ`的`Docker 部署问题`文档。

<Redirect to="/docs/introduction/development/docker/#faq" />

<Tabs items={['Javascript', 'Rust']}> #tabs组件用法,渲染效果参考`introduction`下`development`的`faq`文档
<Tab value="Javascript">Javascript is weird</Tab>
<Tab value="Rust">Rust is fast</Tab>


import FastGPTLink from '@/components/docs/linkFastGPT'; #FastGPT跳转链接组件,通过接收一个域名环境变量,来实现跳转到海外或者国内

本文档介绍了如何设置开发环境以构建和测试 <FastGPTLink>FastGPT</FastGPTLink>。
</Tabs>

```

在书写完文档后,需要在对应的目录下的`meta.json`文件的`pages`字段合适位置添加自己的文件名。例如在`content/docs`(默认这是所有文档的根目录)的`introduction`目录下书写了一个`hello.mdx`文件。则需要去`introduction`目录下的`meta.json`添加以下内容:

```bash
{
"title": "FastGPT Docs",
"root": true,
"pages": ["[Handshake][联系我们](https://fael3z0zfze.feishu.cn/share/base/form/shrcnRxj3utrzjywsom96Px4sud)","index","guide","development","FAQ","shopping_cart","community","hello"], #"hello"原本没有,此外,这里的顺序就是最后文档的展示顺序,现在"hello"文档将会在`introduction`的最后展示
"order": 1
}
```

### Fumadocs MDX
# i18n

A `source.config.ts` config file has been included, you can customise different options like frontmatter schema.
在`content/docs`下的所有`.mdx`文件为默认语言文件(当前默认语言中文),`.en.mdx`文件为`i18n`支持的英文文件,例如,你可以将`hello.mdx`文档翻译后,写一个`hello.en.mdx`,同时,在对应目录的`meta.en.json`的`"pages"`字段写下对应的文件名来支持英文文档。

Read the [Introduction](https://fumadocs.dev/docs/mdx) for further details.
# ps

## Learn More
`meta.json`的`"pages"`中的`"[Handshake][联系我们](https://fael3z0zfze.feishu.cn/share/base/form/shrcnRxj3utrzjywsom96Px4sud)"`这个字段是目录的链接形式,表现效果为,点击后跳转到对应的url。

To learn more about Next.js and Fumadocs, take a look at the following
resources:
![](./public/readme/link.png)

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js
features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- [Fumadocs](https://fumadocs.vercel.app) - learn about Fumadocs
最后,如果依然有问题,可以进入`https://fumadocs.dev/docs/ui`官网,询问官网提供的ai来了解文档框架的使用。
18 changes: 9 additions & 9 deletions document/app/[lang]/(home)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ReactNode } from 'react';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import { baseOptions } from '@/app/layout.config';
import { t } from '@/lib/i18n';
import LogoLight from '@/components/docs/logo';

export default async function Layout({
params,
Expand All @@ -13,13 +12,14 @@ export default async function Layout({
const lang = (await params).lang;
return (
<HomeLayout
{...baseOptions(lang)}
links={[
{
text: t('common:Documentation'),
url: '/docs'
}
]}
nav={{
title: (
<div className="flex flex-row items-center gap-2 h-14">
<LogoLight />
</div>
)
}}
i18n
>
{children}
</HomeLayout>
Expand Down
2 changes: 1 addition & 1 deletion document/app/[lang]/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function HomePage() {
<h1 className="mb-4 text-2xl font-bold">Hello World</h1>
<p className="text-fd-muted-foreground">
You can open{' '}
<Link href="/docs" className="text-fd-foreground font-semibold underline">
<Link href="/docs/introduction" className="text-fd-foreground font-semibold underline">
/docs
</Link>{' '}
and see the documentation.
Expand Down
9 changes: 6 additions & 3 deletions document/app/[lang]/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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';
import { fetchLastModified } from '@/lib/github';

export default async function Page({
params
Expand All @@ -14,6 +15,7 @@ export default async function Page({
if (!page || !page.data || !page.file) notFound();

const MDXContent = page.data.body;
const lastModified = await fetchLastModified(`/content/docs/${page.path}`);

return (
<DocsPage
Expand All @@ -23,11 +25,12 @@ export default async function Page({
style: 'clerk'
}}
editOnGithub={{
owner: 'dreamer6680',
repo: 'fast',
owner: 'labring',
repo: 'FastGPT',
sha: 'main',
path: `content/docs/${page.file.path}`
path: `document/content/docs/${page.file.path}`
}}
lastUpdate={lastModified ? new Date(lastModified) : undefined}
>
<DocsTitle>{page.data.title}</DocsTitle>
<DocsDescription>{page.data.description}</DocsDescription>
Expand Down
95 changes: 92 additions & 3 deletions document/app/[lang]/docs/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import type { ReactNode } from 'react';
import { type ReactNode } from 'react';
import { source } from '@/lib/source';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
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,
Expand All @@ -12,8 +21,88 @@ export default async function Layout({
}) {
const { lang } = await params;

const tab = [
{
title: t('common:introduction', lang),
url: lang === 'zh-CN' ? '/docs/introduction' : '/en/docs/introduction',
className: 'nav-tabs'
},
{
title: t('common:use-cases', lang),
url: lang === 'zh-CN' ? '/docs/use-cases' : '/en/docs/use-cases',
className: 'nav-tabs-link-active-color'
},
// {
// title: t("common:api", lang),
// url: lang === "zh-CN" ? "/docs/api" : "/en/docs/api",
// className: "nav-tabs-link-active-color",
// },
{
title: t('common:protocol', lang),
url: lang === 'zh-CN' ? '/docs/protocol' : '/en/docs/protocol',
className: 'nav-tabs-link-active-color'
}
];

return (
<DocsLayout {...baseOptions(lang)} tree={source.pageTree[lang]}>
<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>
);
Expand Down
8 changes: 8 additions & 0 deletions document/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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']
Expand Down Expand Up @@ -62,6 +63,13 @@ export default async function Layout({
}
}[lang]
}}
search={{
enabled: true,
SearchDialog: CustomSearchDialog
}}
theme={{
enabled: true
}}
>
{children}
</RootProvider>
Expand Down
Loading
Loading