Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kuizuo committed Aug 27, 2024
1 parent 24fd5f9 commit 32784e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 48 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"serve": "docusaurus serve",
"format": "biome format --write ./src",
"lint": "biome check ./src",
"lint:fix": "biome check --apply-unsafe ./src",
"lint:fix": "biome check --write --unsafe ./src",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"index": "docker run -it --env-file=.env -e \"CONFIG=$(cat docsearch.json | jq -r tostring)\" algolia/docsearch-scraper"
Expand Down Expand Up @@ -68,5 +68,5 @@
"engines": {
"node": ">=20.0"
},
"packageManager": "pnpm@9.4.0"
"packageManager": "pnpm@9.8.0"
}
39 changes: 16 additions & 23 deletions src/theme/BlogSidebar/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, {memo, type ReactNode} from 'react';
import {useThemeConfig} from '@docusaurus/theme-common';
import {groupBlogSidebarItemsByYear} from '@docusaurus/plugin-content-blog/client';
import Heading from '@theme/Heading';
import type {Props} from '@theme/BlogSidebar/Content';
import { groupBlogSidebarItemsByYear } from '@docusaurus/plugin-content-blog/client'
import { useThemeConfig } from '@docusaurus/theme-common'
import type { Props } from '@theme/BlogSidebar/Content'
import Heading from '@theme/Heading'
import React, { memo, type ReactNode } from 'react'

function BlogSidebarYearGroup({
year,
yearGroupHeadingClassName,
children,
}: {
year: string;
yearGroupHeadingClassName?: string;
children: ReactNode;
year: string
yearGroupHeadingClassName?: string
children: ReactNode
}) {
return (
<div role="group">
Expand All @@ -20,32 +20,25 @@ function BlogSidebarYearGroup({
</Heading>
{children}
</div>
);
)
}

function BlogSidebarContent({
items,
yearGroupHeadingClassName,
ListComponent,
}: Props): ReactNode {
const themeConfig = useThemeConfig();
function BlogSidebarContent({ items, yearGroupHeadingClassName, ListComponent }: Props): ReactNode {
const themeConfig = useThemeConfig()
if (themeConfig.blog.sidebar.groupByYear) {
const itemsByYear = groupBlogSidebarItemsByYear(items);
const itemsByYear = groupBlogSidebarItemsByYear(items)
return (
<>
{itemsByYear.map(([year, yearItems]) => (
<BlogSidebarYearGroup
key={year}
year={year}
yearGroupHeadingClassName={yearGroupHeadingClassName}>
<BlogSidebarYearGroup key={year} year={year} yearGroupHeadingClassName={yearGroupHeadingClassName}>
<ListComponent items={yearItems} />
</BlogSidebarYearGroup>
))}
</>
);
)
} else {
return <ListComponent items={items} />;
return <ListComponent items={items} />
}
}

export default memo(BlogSidebarContent);
export default memo(BlogSidebarContent)
38 changes: 15 additions & 23 deletions src/theme/BlogSidebar/Mobile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React, {memo} from 'react';
import {
useVisibleBlogSidebarItems,
BlogSidebarItemList,
} from '@docusaurus/plugin-content-blog/client';
import {NavbarSecondaryMenuFiller} from '@docusaurus/theme-common';
import BlogSidebarContent from '@theme/BlogSidebar/Content';
import type {Props} from '@theme/BlogSidebar/Mobile';
import type {Props as BlogSidebarContentProps} from '@theme/BlogSidebar/Content';
import { BlogSidebarItemList, useVisibleBlogSidebarItems } from '@docusaurus/plugin-content-blog/client'
import { NavbarSecondaryMenuFiller } from '@docusaurus/theme-common'
import BlogSidebarContent from '@theme/BlogSidebar/Content'
import type { Props as BlogSidebarContentProps } from '@theme/BlogSidebar/Content'
import type { Props } from '@theme/BlogSidebar/Mobile'
import React, { memo } from 'react'

import styles from './styles.module.css';
import styles from './styles.module.css'

const ListComponent: BlogSidebarContentProps['ListComponent'] = ({items}) => {
const ListComponent: BlogSidebarContentProps['ListComponent'] = ({ items }) => {
return (
<BlogSidebarItemList
items={items}
Expand All @@ -19,27 +16,22 @@ const ListComponent: BlogSidebarContentProps['ListComponent'] = ({items}) => {
linkClassName="menu__link"
linkActiveClassName="menu__link--active"
/>
);
};
)
}

function BlogSidebarMobileSecondaryMenu({sidebar}: Props): JSX.Element {
const items = useVisibleBlogSidebarItems(sidebar.items);
function BlogSidebarMobileSecondaryMenu({ sidebar }: Props): JSX.Element {
const items = useVisibleBlogSidebarItems(sidebar.items)
return (
<BlogSidebarContent
items={items}
ListComponent={ListComponent}
yearGroupHeadingClassName={styles.yearGroupHeading}
/>
);
)
}

function BlogSidebarMobile(props: Props): JSX.Element {
return (
<NavbarSecondaryMenuFiller
component={BlogSidebarMobileSecondaryMenu}
props={props}
/>
);
return <NavbarSecondaryMenuFiller component={BlogSidebarMobileSecondaryMenu} props={props} />
}

export default memo(BlogSidebarMobile);
export default memo(BlogSidebarMobile)

0 comments on commit 32784e9

Please sign in to comment.