Skip to content

Commit

Permalink
Replace render prop with children to simplicity sake
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Jul 15, 2021
1 parent 43ea649 commit 1566a2c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import TOC from '@theme/TOC';
import type {Props} from '@theme/BlogLayout';

function BlogLayout(props: Props): JSX.Element {
const {sidebar, contentRender, toc, ...layoutProps} = props;
const {sidebar, toc, children, ...layoutProps} = props;
const hasSidebar = sidebar && sidebar.items.length > 0;

return (
Expand All @@ -32,7 +32,7 @@ function BlogLayout(props: Props): JSX.Element {
'col--7': hasSidebar,
'col--9': !hasSidebar,
})}>
{contentRender()}
{children}
</main>
{toc && (
<div className="col col--2">
Expand Down
28 changes: 12 additions & 16 deletions packages/docusaurus-theme-classic/src/theme/BlogListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@ function BlogListPage(props: Props): JSX.Element {
// assign unique search tag to exclude this page from search results!
tag: 'blog_posts_list',
}}
sidebar={sidebar}
contentRender={() => (
<>
{items.map(({content: BlogPostContent}) => (
<BlogPostItem
key={BlogPostContent.metadata.permalink}
frontMatter={BlogPostContent.frontMatter}
metadata={BlogPostContent.metadata}
truncated={BlogPostContent.metadata.truncated}>
<BlogPostContent />
</BlogPostItem>
))}
<BlogListPaginator metadata={metadata} />
</>
)}
/>
sidebar={sidebar}>
{items.map(({content: BlogPostContent}) => (
<BlogPostItem
key={BlogPostContent.metadata.permalink}
frontMatter={BlogPostContent.frontMatter}
metadata={BlogPostContent.metadata}
truncated={BlogPostContent.metadata.truncated}>
<BlogPostContent />
</BlogPostItem>
))}
<BlogListPaginator metadata={metadata} />
</BlogLayout>
);
}

Expand Down
28 changes: 13 additions & 15 deletions packages/docusaurus-theme-classic/src/theme/BlogPostPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,23 @@ function BlogPostPage(props: Props): JSX.Element {
wrapperClassName={ThemeClassNames.wrapper.blogPages}
pageClassName={ThemeClassNames.page.blogPostPage}
sidebar={sidebar}
contentRender={() => (
<>
<BlogPostItem
frontMatter={frontMatter}
metadata={metadata}
isBlogPostPage>
<BlogPostContents />
</BlogPostItem>
{(nextItem || prevItem) && (
<BlogPostPaginator nextItem={nextItem} prevItem={prevItem} />
)}
</>
)}
toc={
!hideTableOfContents && BlogPostContents.toc
? BlogPostContents.toc
: undefined
}
/>
}>
<>
<BlogPostItem
frontMatter={frontMatter}
metadata={metadata}
isBlogPostPage>
<BlogPostContents />
</BlogPostItem>
{(nextItem || prevItem) && (
<BlogPostPaginator nextItem={nextItem} prevItem={prevItem} />
)}
</>
</BlogLayout>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ function BlogTagsListPage(props: Props): JSX.Element {
// assign unique search tag to exclude this page from search results!
tag: 'blog_tags_list',
}}
sidebar={sidebar}
contentRender={() => (
<>
<h1>{title}</h1>
<section className="margin-vert--lg">{tagsSection}</section>
</>
)}
/>
sidebar={sidebar}>
<h1>{title}</h1>
<section className="margin-vert--lg">{tagsSection}</section>
</BlogLayout>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,29 @@ function BlogTagsPostPage(props: Props): JSX.Element {
// assign unique search tag to exclude this page from search results!
tag: 'blog_tags_posts',
}}
sidebar={sidebar}
contentRender={() => (
<>
<header className="margin-bottom--xl">
<h1>{title}</h1>
sidebar={sidebar}>
<header className="margin-bottom--xl">
<h1>{title}</h1>

<Link href={allTagsPath}>
<Translate
id="theme.tags.tagsPageLink"
description="The label of the link targeting the tag list page">
View All Tags
</Translate>
</Link>
</header>
<Link href={allTagsPath}>
<Translate
id="theme.tags.tagsPageLink"
description="The label of the link targeting the tag list page">
View All Tags
</Translate>
</Link>
</header>

{items.map(({content: BlogPostContent}) => (
<BlogPostItem
key={BlogPostContent.metadata.permalink}
frontMatter={BlogPostContent.frontMatter}
metadata={BlogPostContent.metadata}
truncated>
<BlogPostContent />
</BlogPostItem>
))}
</>
)}
/>
{items.map(({content: BlogPostContent}) => (
<BlogPostItem
key={BlogPostContent.metadata.permalink}
frontMatter={BlogPostContent.frontMatter}
metadata={BlogPostContent.metadata}
truncated>
<BlogPostContent />
</BlogPostItem>
))}
</BlogLayout>
);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus-theme-classic/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ declare module '@theme/BlogLayout' {
import type {BlogSidebar} from '@theme/BlogSidebar';
import type {TOCItem} from '@docusaurus/types';

export type Props = Omit<LayoutProps, 'children'> & {
export type Props = LayoutProps & {
readonly sidebar?: BlogSidebar;
readonly contentRender: () => React.ReactNode;
readonly toc?: readonly TOCItem[];
};

Expand Down

0 comments on commit 1566a2c

Please sign in to comment.