Skip to content

Commit

Permalink
Merge pull request #34 from HyunmoAhn/env/combine-blogs
Browse files Browse the repository at this point in the history
Env/combine blogs
  • Loading branch information
HyunmoAhn authored Nov 9, 2024
2 parents 3a7f52b + 7f654bb commit ffde7bb
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 23 deletions.
File renamed without changes.
File renamed without changes.
29 changes: 6 additions & 23 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
},
hideOnScroll: true,
items: [
{ to: '/trouble-shooting', label: 'Trouble Shooting', position: 'left' },
{ to: '/tags/trouble-shooting', label: 'Trouble Shooting', position: 'left' },
{ to: '/about', label: 'About', position: 'left' },
{
type: 'localeDropdown',
Expand All @@ -70,28 +70,19 @@ module.exports = {
},
{
label: 'Trouble Shooting',
to: '/trouble-shooting',
to: '/tags/trouble-shooting',
},
{
label: 'About',
to: '/about',
},
{
label: 'GitHub',
href: 'https://github.com/HyunmoAhn',
},
],
},
{
title: 'Tags',
items: [
{
label: 'Blog',
label: 'Tag',
to: '/tags',
},
{
label: 'Trouble Shooting',
to: '/trouble-shooting/tags',
label: 'GitHub',
href: 'https://github.com/HyunmoAhn',
},
],
},
Expand Down Expand Up @@ -139,6 +130,7 @@ module.exports = {
routeBasePath: '/',
showReadingTime: true,
authorsMapPath: '../authors.yml',
blogSidebarCount: 'ALL',
},
theme: {
customCss: [
Expand All @@ -157,15 +149,6 @@ module.exports = {
],
plugins: [
'docusaurus-plugin-sass',
[
'@docusaurus/plugin-content-blog',
{
id: 'trouble-shooting',
routeBasePath: 'trouble-shooting',
path: './troubleShooting',
authorsMapPath: '../authors.yml',
},
],
[
'@docusaurus/plugin-pwa',
{
Expand Down
2 changes: 2 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
--docusaurus-error-code-line-bg: #ffccc080;
--docusaurus-good-code-line-bg: #25a38940;

--ifm-container-width-xl: 1520px;
}

/* If you have a different syntax highlighting theme for dark mode. */
Expand Down
59 changes: 59 additions & 0 deletions src/theme/BlogTagsPostsPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import clsx from 'clsx';
import Translate from '@docusaurus/Translate';
import { PageMetadata, HtmlClassNameProvider, ThemeClassNames } from '@docusaurus/theme-common';
import { useBlogTagsPostsPageTitle } from '@docusaurus/theme-common/internal';
import Link from '@docusaurus/Link';
import BlogLayout from '@theme/BlogLayout';
import BlogListPaginator from '@theme/BlogListPaginator';
import SearchMetadata from '@theme/SearchMetadata';
import type { Props } from '@theme/BlogTagsPostsPage';
import BlogPostItems from '@theme/BlogPostItems';
import Unlisted from '@theme/ContentVisibility/Unlisted';
import Heading from '@theme/Heading';
import { getTaggedSideBar } from '../../utils';

function BlogTagsPostsPageMetadata({ tag }: Props): JSX.Element {
const title = useBlogTagsPostsPageTitle(tag);
return (
<>
<PageMetadata title={title} description={tag.description} />
<SearchMetadata tag="blog_tags_posts" />
</>
);
}

function BlogTagsPostsPageContent({ tag, items, sidebar, listMetadata }: Props): JSX.Element {
const title = useBlogTagsPostsPageTitle(tag);
const taggedSideBar = getTaggedSideBar({ selectTag: tag.label, items, sidebar });

return (
<BlogLayout sidebar={taggedSideBar}>
{tag.unlisted && <Unlisted />}
<header className="margin-bottom--xl">
<Heading as="h1">{title}</Heading>
{tag.description && <p>{tag.description}</p>}
<Link href={tag.allTagsPath}>
<Translate
id="theme.tags.tagsPageLink"
description="The label of the link targeting the tag list page"
>
View All Tags
</Translate>
</Link>
</header>
<BlogPostItems items={items} />
<BlogListPaginator metadata={listMetadata} />
</BlogLayout>
);
}
export default function BlogTagsPostsPage(props: Props): JSX.Element {
return (
<HtmlClassNameProvider
className={clsx(ThemeClassNames.wrapper.blogPages, ThemeClassNames.page.blogTagPostListPage)}
>
<BlogTagsPostsPageMetadata {...props} />
<BlogTagsPostsPageContent {...props} />
</HtmlClassNameProvider>
);
}
25 changes: 25 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { PropBlogPostContent, BlogSidebar } from '@docusaurus/plugin-content-blog';

export interface TaggedSideBarParams {
items: readonly { readonly content: PropBlogPostContent }[];
sidebar: BlogSidebar;
selectTag: string;
}

export const getTaggedSideBar = ({ items, selectTag, sidebar }: TaggedSideBarParams) => {
const taggedContents = items.filter((item) =>
item.content.metadata.tags.some((tag) => {
return tag.label === selectTag;
}),
);

return {
...sidebar,
title: `"${selectTag}" posts`,
items: sidebar.items.filter((item) => {
return taggedContents.some((taggedContent) => {
return item.permalink === taggedContent.content.metadata.permalink;
});
}),
};
};

0 comments on commit ffde7bb

Please sign in to comment.