Skip to content

Commit c080cb1

Browse files
committed
feat: update docs to dumi
1 parent d88d95f commit c080cb1

File tree

746 files changed

+50581
-132268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

746 files changed

+50581
-132268
lines changed

.dumi/hooks/types.ts

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
import type { ExampleBlockAsset } from 'dumi-assets-types';
2+
import type { ComponentType, ReactNode } from 'react';
3+
4+
export interface IPreviewerProps {
5+
/**
6+
* title of current demo
7+
*/
8+
title?: string;
9+
/**
10+
* description of current demo
11+
*/
12+
description?: string;
13+
/**
14+
* filename of current demo
15+
*/
16+
filename?: string;
17+
/**
18+
* use iframe to render demo
19+
*/
20+
iframe?: boolean | number;
21+
/**
22+
* debug mark (will only render in dev by default)
23+
*/
24+
debug?: boolean;
25+
/**
26+
* display the source code or not by default
27+
*/
28+
defaultShowCode?: boolean;
29+
/**
30+
* url for render current demo in a single page
31+
*/
32+
demoUrl: string;
33+
/**
34+
* disable demo content padding
35+
*/
36+
compact?: boolean;
37+
/**
38+
* add transform property for handle absolute/fixed position element
39+
*/
40+
transform?: boolean;
41+
/**
42+
* background color for demo content
43+
*/
44+
background?: string;
45+
/**
46+
* asset metadata of current demo
47+
*/
48+
asset: ExampleBlockAsset;
49+
/**
50+
* react node of current demo
51+
*/
52+
children: ReactNode;
53+
[key: string]: any;
54+
}
55+
56+
export interface IRouteMeta {
57+
// route frontmatter
58+
frontmatter: {
59+
// seo related
60+
title: string;
61+
description?: string;
62+
keywords?: string[];
63+
// render related
64+
nav?:
65+
| string
66+
| {
67+
title?: string;
68+
order?: number;
69+
second?: Omit<IRouteMeta['frontmatter']['nav'], 'second'>;
70+
};
71+
group?: { title?: string; order?: number; index?: boolean } | string;
72+
subGroup?: { title?: string };
73+
order?: number;
74+
hero?: {
75+
title?: string;
76+
description?: string;
77+
background?: string;
78+
actions?: { text: string; link: string }[];
79+
[key: string]: any;
80+
};
81+
features?: {
82+
emoji?: string;
83+
title?: string;
84+
link?: string;
85+
description?: string;
86+
[key: string]: any;
87+
}[];
88+
toc?: boolean | 'content' | 'menu';
89+
demo?: {
90+
cols?: number;
91+
tocDepth?: number;
92+
};
93+
atomId?: string;
94+
filename?: string;
95+
lastUpdated?: number;
96+
debug?: boolean;
97+
/**
98+
* Control the display of the sidebar menu.
99+
* @default true
100+
*/
101+
sidebar?: boolean;
102+
[key: string]: any;
103+
};
104+
// route toc
105+
toc: {
106+
id: string;
107+
depth: number;
108+
title: string;
109+
/**
110+
* private field, do not use it in your code
111+
*/
112+
_debug_demo?: boolean;
113+
}[];
114+
// route texts
115+
texts: {
116+
type?: 'content';
117+
value: string;
118+
/**
119+
* paragraph index
120+
*/
121+
paraId: number;
122+
/**
123+
* title index in toc
124+
*/
125+
tocIndex?: number;
126+
}[];
127+
// tabs
128+
tabs?: {
129+
key: string;
130+
title?: string;
131+
titleIntlId?: string;
132+
components: {
133+
default: ComponentType;
134+
Extra: ComponentType;
135+
Action: ComponentType;
136+
};
137+
meta: {
138+
frontmatter: Omit<
139+
IRouteMeta['frontmatter'],
140+
'description' | 'keywords' | 'nav' | 'group' | 'hero' | 'features'
141+
>;
142+
toc: IRouteMeta['toc'];
143+
texts: IRouteMeta['texts'];
144+
[key: string]: any;
145+
};
146+
}[];
147+
/**
148+
* private field, do not use it in your code
149+
*/
150+
_atom_route?: boolean;
151+
}
152+
153+
type IBasicLocale = { id: string; name: string };
154+
export type ILocale =
155+
| (IBasicLocale & { base: string })
156+
| (IBasicLocale & { suffix: string });
157+
export type ILocalesConfig = ILocale[];
158+
159+
export interface INavItem {
160+
title: string;
161+
link?: string;
162+
order?: number;
163+
activePath?: string;
164+
[key: string]: any;
165+
}
166+
export interface ISidebarItem {
167+
title: string;
168+
link: string;
169+
order?: number;
170+
frontmatter?: IRouteMeta['frontmatter'];
171+
[key: string]: any;
172+
}
173+
export interface ISidebarGroup {
174+
title?: string;
175+
children: ISidebarItem[];
176+
[key: string]: any;
177+
}
178+
export type SocialTypes =
179+
| 'github'
180+
| 'weibo'
181+
| 'twitter'
182+
| 'gitlab'
183+
| 'facebook'
184+
| 'zhihu'
185+
| 'yuque'
186+
| 'linkedin';
187+
188+
export type INavItems = (INavItem & { children?: INavItem[] })[];
189+
export type INav = INavItems | Record<string, INavItems>;
190+
type IUserNavItem = Pick<INavItem, 'title' | 'link' | 'activePath'>;
191+
export type IUserNavMode = 'override' | 'append' | 'prepend';
192+
export type IUserNavItems = (IUserNavItem & { children?: IUserNavItem[] })[];
193+
export type IUserNavValue = IUserNavItems | Record<string, IUserNavItems>;
194+
export type NavWithMode<T extends IUserNavValue> = {
195+
/**
196+
* 扩展导航的模式
197+
* @description
198+
* - 'override': 用 value 中配置的导航直接覆盖约定路由的导航
199+
* - 'append': 将 value 中配置的导航追加到约定路由导航后面
200+
* - 'prepend': 将 value 中配置的导航添加到约定路由导航前面
201+
*/
202+
mode: IUserNavMode;
203+
value: T;
204+
};
205+
206+
export interface IThemeConfig {
207+
name?: string;
208+
logo?: string | false;
209+
nav?: IUserNavValue | NavWithMode<IUserNavValue>;
210+
sidebar?: Record<string, ISidebarGroup[]>;
211+
footer?: string | false;
212+
showLineNum?: boolean;
213+
prefersColor: {
214+
default: 'light' | 'dark' | 'auto';
215+
switch: boolean;
216+
};
217+
nprogress?: boolean;
218+
socialLinks?: {
219+
/**
220+
* 形如:github: "https://github.com/umijs/dumi"
221+
*/
222+
[key in SocialTypes]?: string;
223+
};
224+
editLink?: boolean | string;
225+
lastUpdated?: boolean;
226+
[key: string]: any;
227+
}
228+
229+
export type IRoutesById = Record<
230+
string,
231+
{
232+
path?: string;
233+
parentId?: string;
234+
meta?: IRouteMeta;
235+
id: string;
236+
redirect?: string;
237+
[key: string]: any;
238+
}
239+
>;

.dumi/hooks/useLocale.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useIntl, useSiteData } from 'dumi';
2+
import { useState } from 'react';
3+
import type { ILocale } from './types';
4+
5+
export const useLocale = (): ILocale => {
6+
const intl = useIntl();
7+
const { locales } = useSiteData();
8+
const [locale] = useState(
9+
() => locales.find(({ id }) => id === intl.locale)!,
10+
);
11+
return locale;
12+
};

0 commit comments

Comments
 (0)