Skip to content

Commit

Permalink
refactor: getMetaByRouteId return metainfo for all routes (#2134)
Browse files Browse the repository at this point in the history
* refactor: getMetaByRouteId return metainfo for all routes

* fix: frontmatter is an object

* fix: 分号
  • Loading branch information
Jinbao1001 committed Jun 3, 2024
1 parent 1e98477 commit 8fa976d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/templates/meta/exports.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ export function getRouteMetaById<T extends { syncOnly?: boolean }>(
id: string,
opts?: T,
): T extends { syncOnly: true }
? IRouteMeta | undefined
: Promise<IRouteMeta> | undefined {
if (filesMeta[id]) {
const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
const routeMeta: IRouteMeta = {
frontmatter,
toc: toc,
? IRouteMeta
: Promise<IRouteMeta> {
const routeMeta: IRouteMeta = {
frontmatter: {},
toc: [],
texts: [],
};
if (filesMeta[id]) {
const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
routeMeta.frontmatter = frontmatter;
routeMeta.toc = toc;

if (opts?.syncOnly) {
if (tabs) {
Expand Down Expand Up @@ -174,6 +176,10 @@ export function getRouteMetaById<T extends { syncOnly?: boolean }>(
});
}
}
if (opts?.syncOnly) {
return routeMeta;
}
return Promise.resolve(routeMeta);
}

/**
Expand Down

0 comments on commit 8fa976d

Please sign in to comment.