docs: 引入 Fumadocs

ci: set up github actions
This commit is contained in:
Palm Civet
2025-09-05 20:00:05 +08:00
parent f89a17f14d
commit 29232afadc
32 changed files with 1422 additions and 4 deletions

View File

@@ -0,0 +1,19 @@
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
/**
* Shared layout configurations
*/
export function baseOptions(): BaseLayoutProps {
return {
githubUrl: 'https://github.com/nagisa77/OpenIsle',
nav: {
title: 'OpenIsle Docs',
url: '/docs',
},
searchToggle: {
enabled: false,
},
// see https://fumadocs.dev/docs/ui/navigation/links
links: [],
};
}

View File

@@ -0,0 +1,4 @@
'use client';
// forward them so that Fumadocs can also use your media adapter in a client component
export { OpenIsleMediaAdapter } from './media-adapter';

23
docs/lib/media-adapter.ts Normal file
View File

@@ -0,0 +1,23 @@
import type { MediaAdapter } from 'fumadocs-openapi';
export const OpenIsleMediaAdapter: MediaAdapter = {
encode(data) {
return JSON.stringify(data.body);
},
// returns code that inits a `body` variable, used for request body
generateExample(data, ctx) {
if (ctx.lang === 'js') {
return `const body = "hello world"`;
}
if (ctx.lang === 'python') {
return `body = "hello world"`;
}
if (ctx.lang === 'go' && 'addImport' in ctx) {
ctx.addImport('strings');
return `body := strings.NewReader("hello world")`;
}
},
};

5
docs/lib/openapi.ts Normal file
View File

@@ -0,0 +1,5 @@
import { createOpenAPI } from 'fumadocs-openapi/server';
export const openapi = createOpenAPI({
input: ['https://staging.open-isle.com/api/v3/api-docs'],
});

37
docs/lib/source.ts Normal file
View File

@@ -0,0 +1,37 @@
import { createElement } from 'react';
import { icons } from 'lucide-react';
import { loader } from 'fumadocs-core/source';
import { transformerOpenAPI } from 'fumadocs-openapi/server';
import { createOpenAPI } from 'fumadocs-openapi/server';
import { docs } from '@/.source';
import * as Adapters from './media-adapter';
import * as ClientAdapters from './media-adapter.client';
// See https://fumadocs.vercel.app/docs/headless/source-api for more info
export const source = loader({
// it assigns a URL to your pages
baseUrl: '/docs',
source: docs.toFumadocsSource(),
pageTree: {
transformers: [transformerOpenAPI()],
},
icon(icon) {
if (!icon) {
return;
}
if (icon in icons) {
return createElement(icons[icon as keyof typeof icons]);
}
},
});
export const openapi = createOpenAPI({
proxyUrl: '/api/proxy',
mediaAdapters: {
// override the default adapter of `application/json`
'application/json': {
...Adapters.OpenIsleMediaAdapter,
client: ClientAdapters.OpenIsleMediaAdapter,
},
},
});