Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: useRouteMeta & useTabMeta with getRouteMetaById #1888

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: route meta
  • Loading branch information
MadCcc committed Sep 12, 2023
commit 40595ab67aa7f9177676a5a88b1737b16875e5e5
2 changes: 1 addition & 1 deletion src/client/theme-api/useRouteMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 15,7 @@ const useAsyncRouteMeta = (id: string) => {
cache.set(id, getRouteMetaById(id));
}

return use(cache.get(id));
return use<ReturnType<getRouteMetaById>>(cache.get(id));
};

/**
Expand Down
4 changes: 1 addition & 3 deletions src/client/theme-default/slots/ContentTabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 18,6 @@ const ContentTabs: FC<IContentTabsProps> = ({
const intl = useIntl();

// TODO: tab.Extra & tab.Action render
console.log(tabs);

return Boolean(tabs?.length) ? (
<ul className="dumi-default-content-tabs">
<li onClick={() => onChange()} data-active={!key || undefined}>
Expand All @@ -36,7 34,7 @@ const ContentTabs: FC<IContentTabsProps> = ({
<button type="button">
{tab.titleIntlId
? intl.formatMessage({ id: tab.titleIntlId })
: tab.meta.frontmatter?.title ?? tab.title}
: tab.meta.frontmatter.title}
</button>
</li>
))}
Expand Down
8 changes: 6 additions & 2 deletions src/templates/meta-route.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 16,18 @@ export const getRouteMetaById = async (id: string) => {
const file = files[id];

if (!file) {
return {};
return null;
}

const text = await file.textGetter();
const frontmatter = await file.frontmatterGetter();

const tabsMeta = file.tabs && await Promise.all(file.tabs.map(async (tab) => {
const meta = await getRouteMetaById(tab)
const meta = await getRouteMetaById(tab) ?? {
frontmatter: { title: tabs[tab].title },
toc: [],
texts: [],
};
return {
...tabs[tab],
meta,
Expand Down