From 04da1f3fdfa10df7cc306a30915c3d93842e72d6 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 17 Nov 2022 01:22:09 +0800 Subject: [PATCH] docs: fix site issue --- .dumi/theme/builtins/DemoWrapper/index.tsx | 10 +++------- .dumi/theme/slots/Content/index.tsx | 7 +++++-- .dumi/theme/slots/DemoContext.tsx | 2 -- components/float-button/index.en-US.md | 2 +- components/float-button/index.zh-CN.md | 2 +- scripts/check-site.js | 15 +++++++-------- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/.dumi/theme/builtins/DemoWrapper/index.tsx b/.dumi/theme/builtins/DemoWrapper/index.tsx index 54f4a29770..9cdb74256f 100644 --- a/.dumi/theme/builtins/DemoWrapper/index.tsx +++ b/.dumi/theme/builtins/DemoWrapper/index.tsx @@ -6,7 +6,7 @@ import classNames from 'classnames'; import DemoContext from '../../slots/DemoContext'; const DemoWrapper: typeof DumiDemoGrid = ({ items }) => { - const { showDebug, setShowDebug, setDebugDemos } = useContext(DemoContext); + const { showDebug, setShowDebug } = useContext(DemoContext); const [expandAll, setExpandAll] = useState(false); @@ -18,16 +18,12 @@ const DemoWrapper: typeof DumiDemoGrid = ({ items }) => { setShowDebug?.(!showDebug); }; - useLayoutEffect(() => { - setDebugDemos?.(items.filter(item => item.previewerProps.debug).map(item => item.demo.id)); - }, []); - const handleExpandToggle = () => { setExpandAll(!expandAll); }; - const visibleDemos = showDebug ? items : items.filter(item => !item.previewerProps.debug); - const filteredItems = visibleDemos.map(item => ({ + const visibleDemos = showDebug ? items : items.filter((item) => !item.previewerProps.debug); + const filteredItems = visibleDemos.map((item) => ({ ...item, previewerProps: { ...item.previewerProps, expand: expandAll }, })); diff --git a/.dumi/theme/slots/Content/index.tsx b/.dumi/theme/slots/Content/index.tsx index c7c0dddd85..6efd27e199 100644 --- a/.dumi/theme/slots/Content/index.tsx +++ b/.dumi/theme/slots/Content/index.tsx @@ -115,14 +115,17 @@ const Content: FC<{ children: ReactNode }> = ({ children }) => { const { direction } = useContext(SiteContext); const [showDebug, setShowDebug] = useState(false); - const [debugDemos, setDebugDemos] = useState([]); + const debugDemos = useMemo( + () => meta.toc?.filter((item) => item._debug_demo).map((item) => item.id) || [], + [meta], + ); useLayoutEffect(() => { setShowDebug(process.env.NODE_ENV === 'development'); }, []); const contextValue = useMemo( - () => ({ showDebug, setShowDebug, debugDemos, setDebugDemos }), + () => ({ showDebug, setShowDebug }), [showDebug, debugDemos], ); diff --git a/.dumi/theme/slots/DemoContext.tsx b/.dumi/theme/slots/DemoContext.tsx index 27a2b5e12d..d377a4207b 100644 --- a/.dumi/theme/slots/DemoContext.tsx +++ b/.dumi/theme/slots/DemoContext.tsx @@ -7,8 +7,6 @@ export type DemoContextProps = { const DemoContext = createContext<{ showDebug?: boolean; setShowDebug?: (showDebug: boolean) => void; - debugDemos?: string[]; - setDebugDemos?: (visibleItems: string[]) => void; }>({}); export default DemoContext; diff --git a/components/float-button/index.en-US.md b/components/float-button/index.en-US.md index f4d4b7b747..8924f714fd 100644 --- a/components/float-button/index.en-US.md +++ b/components/float-button/index.en-US.md @@ -21,7 +21,7 @@ FloatButton. Available since `5.0.0`. Shape Description FloatButton with tooltip -FloatButton Group +FloatButton Group Menu mode BackTop \_InternalPanelDoNotUseOrYouWillBeFired diff --git a/components/float-button/index.zh-CN.md b/components/float-button/index.zh-CN.md index 1c495522d8..0736769da8 100644 --- a/components/float-button/index.zh-CN.md +++ b/components/float-button/index.zh-CN.md @@ -22,7 +22,7 @@ demo: 形状 描述 含有气泡卡片的悬浮按钮 -浮动按钮组 +浮动按钮组 菜单模式 回到顶部 \_InternalPanelDoNotUseOrYouWillBeFired diff --git a/scripts/check-site.js b/scripts/check-site.js index fbf1257d4f..448c1f6f29 100755 --- a/scripts/check-site.js +++ b/scripts/check-site.js @@ -14,14 +14,14 @@ const components = uniq( cwd: join(process.cwd()), dot: false, }) - .map(path => path.replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '')), + .map((path) => path.replace(/(\/index)?((\.zh-cn)|(\.en-us))?\.md$/i, '')), ); describe('site test', () => { let server; const port = 3000; - const render = async path => { - const resp = await fetch(`http://127.0.0.1:${port}${path}`).then(async res => { + const render = async (path) => { + const resp = await fetch(`http://127.0.0.1:${port}${path}`).then(async (res) => { const html = await res.text(); const $ = cheerio.load(html, { decodeEntities: false, recognizeSelfClosing: true }); return { @@ -33,12 +33,12 @@ describe('site test', () => { return resp; }; - const handleComponentName = name => { + const handleComponentName = (name) => { const componentName = name.split('/')[1]; return componentName.toLowerCase().replace('-', ''); }; - const expectComponent = async component => { + const expectComponent = async (component) => { const { status, $ } = await render(`/${component}/`); expect(status).toBe(200); expect($('h1').text().toLowerCase()).toMatch(handleComponentName(component)); @@ -59,8 +59,7 @@ describe('site test', () => { } }); - // FIXME: should not skip if helmet is done - it.skip('Basic Pages en', async () => { + it('Basic Pages en', async () => { const { status, $ } = await render('/'); expect($('title').text()).toEqual( `Ant Design - The world's second most popular React UI framework`, @@ -68,7 +67,7 @@ describe('site test', () => { expect(status).toBe(200); }); - it.skip('Basic Pages zh', async () => { + it('Basic Pages zh', async () => { const { status, $ } = await render('/index-cn'); expect($('title').text()).toEqual(`Ant Design - 一套企业级 UI 设计语言和 React 组件库`); expect(status).toBe(200);