-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blog): group sidebar items by year (`themeConfig.blog.sidebar.gr…
…oupByYear`) (#10252) Co-authored-by: sebastien <lorber.sebastien@gmail.com>
- Loading branch information
1 parent
10830ce
commit aab1f48
Showing
21 changed files
with
547 additions
and
85 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
57 changes: 57 additions & 0 deletions
57
packages/docusaurus-theme-classic/src/theme/BlogSidebar/Content/index.tsx
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import React, {memo, type ReactNode} from 'react'; | ||
import {useThemeConfig} from '@docusaurus/theme-common'; | ||
import {groupBlogSidebarItemsByYear} from '@docusaurus/theme-common/internal'; | ||
import Heading from '@theme/Heading'; | ||
import type {Props} from '@theme/BlogSidebar/Content'; | ||
|
||
function BlogSidebarYearGroup({ | ||
year, | ||
yearGroupHeadingClassName, | ||
children, | ||
}: { | ||
year: string; | ||
yearGroupHeadingClassName?: string; | ||
children: ReactNode; | ||
}) { | ||
return ( | ||
<div role="group"> | ||
<Heading as="h3" className={yearGroupHeadingClassName}> | ||
{year} | ||
</Heading> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
function BlogSidebarContent({ | ||
items, | ||
yearGroupHeadingClassName, | ||
ListComponent, | ||
}: Props): ReactNode { | ||
const themeConfig = useThemeConfig(); | ||
if (themeConfig.blog.sidebar.groupByYear) { | ||
const itemsByYear = groupBlogSidebarItemsByYear(items); | ||
return ( | ||
<> | ||
{itemsByYear.map(([year, yearItems]) => ( | ||
<BlogSidebarYearGroup | ||
key={year} | ||
year={year} | ||
yearGroupHeadingClassName={yearGroupHeadingClassName}> | ||
<ListComponent items={yearItems} /> | ||
</BlogSidebarYearGroup> | ||
))} | ||
</> | ||
); | ||
} else { | ||
return <ListComponent items={items} />; | ||
} | ||
} | ||
|
||
export default memo(BlogSidebarContent); |
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 |
---|---|---|
|
@@ -43,3 +43,8 @@ | |
display: none; | ||
} | ||
} | ||
|
||
.yearGroupHeading { | ||
margin-top: 1.6rem; | ||
margin-bottom: 0.4rem; | ||
} |
Oops, something went wrong.