-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge chunk & optimize meta loading (#1906)
* feat: use new loader for search * feat: search support tsx * feat: split meta chunk * feat: load meta on hover * chore: code clena
- Loading branch information
Showing
12 changed files
with
133 additions
and
132 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
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
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 |
---|---|---|
@@ -1,43 +1,41 @@ | ||
// This will bundle all the site demos and meta data into one file | ||
// which should only async load on search | ||
const filesMetaTabs = { | ||
{{#metaFiles}} | ||
{{#tabs}} | ||
'{{{id}}}': {{{tabs}}}, | ||
{{/tabs}} | ||
{{/metaFiles}} | ||
} | ||
import { getRouteMetaById } from './route-meta'; | ||
import { demoIndexes } from './demos'; | ||
import { filesFrontmatter } from './frontmatter'; | ||
|
||
// generate demos data in runtime, for reuse route.id to reduce bundle size | ||
export const demos = {}; | ||
|
||
/** @private Internal usage. Safe to refactor. */ | ||
export async function loadFilesMeta() { | ||
export async function loadFilesMeta(idList: string[]) { | ||
const metaMap: Record<string, any> = {}; | ||
const idList = [ | ||
{{#metaFiles}} | ||
'{{{id}}}', | ||
{{/metaFiles}} | ||
]; | ||
|
||
{{#metaFiles}} | ||
metaMap['{{{id}}}'] = import('{{{file}}}?type=meta'); | ||
if (idList.includes('{{{id}}}')) { | ||
metaMap['{{{id}}}'] = async () => { | ||
const routeMeta = await getRouteMetaById('{{{id}}}'); | ||
const demo = await demoIndexes['{{{id}}}']?.getter() || {}; | ||
return { | ||
frontmatter: filesFrontmatter['{{{id}}}'] ?? {}, | ||
toc: routeMeta?.toc ?? [], | ||
texts: routeMeta?.texts ?? [], | ||
tabs: routeMeta?.tabs ?? [], | ||
demos: demo?.demos ?? {}, | ||
}; | ||
}; | ||
} | ||
{{/metaFiles}} | ||
|
||
// Wait for all meta data to be loaded | ||
const metaList = await Promise.all(idList.map(id => metaMap[id])); | ||
const metaList = await Promise.all(Object.entries(metaMap).map(([id, getter]) => getter())); | ||
|
||
// Merge into filesMeta | ||
const filesMeta = {}; | ||
|
||
idList.forEach((id, index) => { | ||
const meta = metaList[index]; | ||
filesMeta[id] = { | ||
...meta, | ||
tabs: filesMetaTabs[id], | ||
}; | ||
Object.entries(metaMap).forEach(([id], index) => { | ||
filesMeta[id] = metaList[index]; | ||
}); | ||
|
||
return filesMeta; | ||
} | ||
} |
Oops, something went wrong.