-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
262248d
commit 26740ba
Showing
24 changed files
with
335 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getRouteMetaById, useMatchedRoute } from 'dumi'; | ||
import type { IRouteMeta } from 'dumi/dist/client/theme-api/types'; | ||
import useSWR from 'swr'; | ||
|
||
import { useStoreApi } from '../../store/useSiteStore'; | ||
|
||
const EMPTY_META = { | ||
frontmatter: {}, | ||
texts: [], | ||
toc: [], | ||
} as any; | ||
|
||
// https://github.com/umijs/dumi/pull/2165 | ||
export const useRouteMeta = () => { | ||
const storeApi = useStoreApi(); | ||
const matched = useMatchedRoute(); | ||
|
||
const merge = (meta: IRouteMeta = EMPTY_META) => { | ||
if (matched.meta) { | ||
for (const key of Object.keys(matched.meta)) { | ||
(meta as any)[key] ??= (matched.meta as any)[key]; | ||
} | ||
} | ||
return meta; | ||
}; | ||
|
||
useSWR(matched.id, getRouteMetaById, { | ||
fallback: EMPTY_META, | ||
onSuccess: (meta) => { | ||
storeApi.setState({ routeMeta: merge(meta) }); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ThemeProvider } from '@lobehub/ui'; | ||
import isEqual from 'fast-deep-equal'; | ||
import { PropsWithChildren, memo } from 'react'; | ||
|
||
import GlobalStyle from '@/layouts/DocLayout/GlobalStyle'; | ||
import { siteSelectors, useSiteStore, useThemeStore } from '@/store'; | ||
import customToken from '@/styles/customToken'; | ||
|
||
export default memo<PropsWithChildren>(({ children }) => { | ||
const themeMode = useThemeStore((st) => st.themeMode); | ||
const userToken = useSiteStore(siteSelectors.token, isEqual); | ||
|
||
return ( | ||
<ThemeProvider | ||
customToken={(themeToken) => Object.assign({}, customToken(themeToken), userToken)} | ||
themeMode={themeMode} | ||
> | ||
<GlobalStyle /> | ||
{children} | ||
</ThemeProvider> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
import { ThemeProvider } from '@lobehub/ui'; | ||
import { memo } from 'react'; | ||
import { shallow } from 'zustand/shallow'; | ||
import { | ||
useLocale, | ||
useLocation, | ||
useNavData, | ||
useRouteMeta, | ||
useSidebarData, | ||
useSiteData, | ||
useTabMeta, | ||
} from 'dumi'; | ||
import { memo, useMemo } from 'react'; | ||
|
||
import Favicons from '@/components/Favicons'; | ||
import { StoreUpdater } from '@/components/StoreUpdater'; | ||
import GlobalStyle from '@/layouts/DocLayout/GlobalStyle'; | ||
import { siteSelectors, useSiteStore, useThemeStore } from '@/store'; | ||
import customToken from '@/styles/customToken'; | ||
import { Provider, createStore } from '@/store'; | ||
|
||
import DocumentLayout from './DocumentLayout'; | ||
import ThemeProvider from './ThemeProvider'; | ||
|
||
const App = memo(() => { | ||
const themeMode = useThemeStore((st) => st.themeMode, shallow); | ||
const userToken = useSiteStore(siteSelectors.token); | ||
|
||
const App = memo(({ initState }: any) => { | ||
return ( | ||
<> | ||
<Provider createStore={() => createStore(initState)}> | ||
<Favicons /> | ||
<StoreUpdater /> | ||
<ThemeProvider | ||
customToken={(themeToken) => Object.assign({}, customToken(themeToken), userToken)} | ||
themeMode={themeMode} | ||
> | ||
<GlobalStyle /> | ||
<ThemeProvider> | ||
<DocumentLayout /> | ||
</ThemeProvider> | ||
</> | ||
</Provider> | ||
); | ||
}); | ||
|
||
export default App; | ||
export default memo(() => { | ||
const siteData = useSiteData(); | ||
const sidebar = useSidebarData(); | ||
const routeMeta = useRouteMeta(); | ||
const tabMeta = useTabMeta(); | ||
const navData = useNavData(); | ||
const location = useLocation(); | ||
const locale = useLocale(); | ||
|
||
const initState = useMemo( | ||
() => ({ locale, location, navData, routeMeta, sidebar, siteData, tabMeta }), | ||
[], | ||
); | ||
|
||
return <App initState={initState} />; | ||
}); |
Oops, something went wrong.