refactor: mark toc in loaded MDX as non-optional (#7524)

This commit is contained in:
Joshua Chen 2022-05-29 22:36:41 +08:00 committed by GitHub
parent 8b1acb50d1
commit f443e992b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 18 deletions

View file

@ -328,8 +328,6 @@ declare module '@theme/DocSidebar' {
readonly sidebar: readonly PropSidebarItem[];
readonly onCollapse: () => void;
readonly isHidden: boolean;
// MobileSecondaryFilter expects Record<string, unknown>
readonly [key: string]: unknown;
}
export default function DocSidebar(props: Props): JSX.Element;

View file

@ -65,9 +65,7 @@ function BlogPostPageContent(props: Props): JSX.Element {
<BlogLayout
sidebar={sidebar}
toc={
!hideTableOfContents &&
BlogPostContents.toc &&
BlogPostContents.toc.length > 0 ? (
!hideTableOfContents && BlogPostContents.toc.length > 0 ? (
<TOC
toc={BlogPostContents.toc}
minHeadingLevel={tocMinHeadingLevel}

View file

@ -27,7 +27,7 @@ export default function DocCardList({items, className}: Props): JSX.Element {
<section className={clsx('row', className)}>
{filterItems(items).map((item, index) => (
<article key={index} className="col col--6 margin-bottom--lg">
<DocCard key={index} item={item} />
<DocCard item={item} />
</article>
))}
</section>

View file

@ -55,8 +55,7 @@ function DocItemContent(props: Props): JSX.Element {
const windowSize = useWindowSize();
const canRenderTOC =
!hideTableOfContents && DocContent.toc && DocContent.toc.length > 0;
const canRenderTOC = !hideTableOfContents && DocContent.toc.length > 0;
const renderTocDesktop =
canRenderTOC && (windowSize === 'desktop' || windowSize === 'ssr');

View file

@ -42,7 +42,7 @@ export default function MDXPage(props: Props): JSX.Element {
<MDXPageContent />
</MDXContent>
</div>
{!hideTableOfContents && MDXPageContent.toc && (
{!hideTableOfContents && MDXPageContent.toc.length > 0 && (
<div className="col col--2">
<TOC
toc={MDXPageContent.toc}