Skip to content

Commit 486b0d0

Browse files
committed
refactor: re-structure directory
1 parent 6df49c4 commit 486b0d0

File tree

18 files changed

+186
-131
lines changed

18 files changed

+186
-131
lines changed

content/posts/test1.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: post2
2+
title: 매우 아주 긴 제목입니다 이 제목은 너무 길어서 잘릴 것입니다
33
slug: /test-path
44
date: 2024-11-11
55
category: JavaScript

src/components/displays/PostCard.tsx renamed to src/components/displays/PostCard/PostCard.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from "react";
2-
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "../ui/card";
2+
33
import { NotebookPen } from "lucide-react";
44
import { Link } from "gatsby";
55
import { categoryColor, CategoryKey } from "@/constants/categories";
66
import { toPlainText } from "@/lib/toPlainText";
7+
import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card";
78

89
export interface PostCardProps {
910
slug: string;
@@ -40,11 +41,3 @@ export const PostCard = ({ slug, title, category, content, date }: PostCardProps
4041
</Link>
4142
);
4243
};
43-
44-
export interface PostCardContainerProps {
45-
children: React.ReactNode;
46-
}
47-
48-
export const PostCardContainer = ({ children }: PostCardContainerProps) => {
49-
return <ul className="grid grid-cols-1 gap-2 md:grid-cols-2">{children}</ul>;
50-
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from "react";
2+
3+
export interface PostCardContainerProps {
4+
children: React.ReactNode;
5+
}
6+
7+
export const PostCardContainer = ({ children }: PostCardContainerProps) => {
8+
return <ul className="grid grid-cols-1 gap-2 md:grid-cols-2">{children}</ul>;
9+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { PostCard } from "./PostCard";
2+
export { PostCardContainer } from "./PostCardContainer";

src/components/displays/PostList/PostListContainer.tsx

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import { categoryColor, CategoryKey } from "@/constants/categories";
3+
import { Link } from "gatsby";
4+
import { toPlainText } from "@/lib/toPlainText";
5+
6+
export interface PostCardProps {
7+
slug: string;
8+
9+
title: string;
10+
category: CategoryKey;
11+
content: string;
12+
date: string;
13+
}
14+
15+
export const PostListItem = ({ slug, title, category, content, date }: PostCardProps) => {
16+
return (
17+
<Link to={`/posts${slug}`}>
18+
<div className="border-b-[1px] border-[#3d444d] py-4">
19+
<h1 className="pb-2 text-xl font-bold text-white hover:underline">{title}</h1>
20+
<p className="line-clamp-2 text-sm text-[#9198a1]">{toPlainText(content)}</p>
21+
<div className="flex items-center py-2">
22+
<div
23+
className={`mr-1 aspect-square h-[12px] w-[12px] rounded-full`}
24+
style={{
25+
backgroundColor: categoryColor[category],
26+
}}
27+
></div>
28+
<p className="text-sm text-[#9198a1]">{category}</p>
29+
</div>
30+
</div>
31+
</Link>
32+
);
33+
};

src/components/displays/PostList/index.tsx

Whitespace-only changes.

src/components/navigations/CategoryMenu.tsx

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React from "react";
2+
import { graphql, useStaticQuery } from "gatsby";
3+
4+
import { CategoryMenuItem } from ".";
5+
import { CategoryKey } from "@/constants/categories";
6+
7+
export interface CategoryMenuQuery {
8+
allMdx: {
9+
group: {
10+
edges: {
11+
node: {
12+
frontmatter: {
13+
title: string;
14+
category: CategoryKey;
15+
slug: string;
16+
};
17+
};
18+
}[];
19+
}[];
20+
};
21+
}
22+
23+
export const categoryMenuQuery = graphql`
24+
query {
25+
allMdx {
26+
group(field: { frontmatter: { category: SELECT } }) {
27+
edges {
28+
node {
29+
frontmatter {
30+
title
31+
category
32+
slug
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
`;
40+
41+
export const CategoryMenu = () => {
42+
const data = useStaticQuery<CategoryMenuQuery>(categoryMenuQuery);
43+
44+
const categories = data.allMdx.group.map((category) => {
45+
return {
46+
category: category.edges[0].node.frontmatter.category,
47+
content: category.edges.map((post) => {
48+
return {
49+
title: post.node.frontmatter.title,
50+
slug: post.node.frontmatter.slug,
51+
};
52+
}),
53+
};
54+
});
55+
56+
return (
57+
<aside className="w-[30%] p-2 text-white">
58+
<h2 className="font-bold">Categories</h2>
59+
<nav className="py-2">
60+
{categories.map((category) => {
61+
return <CategoryMenuItem category={category.category} contents={category.content} />;
62+
})}
63+
</nav>
64+
</aside>
65+
);
66+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
2+
import { categoryColor, CategoryKey } from "@/constants/categories";
3+
import { Link } from "gatsby";
4+
import React from "react";
5+
6+
export interface CategoryMenuItemProps {
7+
category: CategoryKey;
8+
contents: {
9+
title: string;
10+
slug: string;
11+
}[];
12+
}
13+
14+
export const CategoryMenuItem = ({ category, contents }: CategoryMenuItemProps) => {
15+
return (
16+
<Accordion type="single" collapsible className="w-full">
17+
<AccordionItem value="item-1" className="border-none">
18+
<AccordionTrigger className="h-[22px] rounded-[4px] border-none px-2 hover:bg-[#161a21]">
19+
<div className="flex items-center justify-start hover:no-underline">
20+
<div
21+
className="mr-1 h-[12px] w-[12px] rounded-full"
22+
style={{ backgroundColor: categoryColor[category] }}
23+
/>
24+
<p className="hover:no-underline">{category}</p>
25+
</div>
26+
</AccordionTrigger>
27+
<AccordionContent className="pb-2">
28+
{contents.map((content) => {
29+
return (
30+
<Link to={`/posts${content.slug}`}>
31+
<p className="overflow-hidden text-ellipsis text-nowrap py-2 pl-8 hover:underline">
32+
{content.title}
33+
</p>
34+
</Link>
35+
);
36+
})}
37+
</AccordionContent>
38+
</AccordionItem>
39+
</Accordion>
40+
);
41+
};

0 commit comments

Comments
 (0)