-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d109863
commit a3ba3dc
Showing
8 changed files
with
124 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,27 @@ | ||
import PostCardList from './components/PostCardList'; | ||
import TopBar from './components/TopBar'; | ||
import { resolve } from 'path'; | ||
import { readFile, readdir } from 'fs/promises'; | ||
import fm from 'front-matter'; | ||
import { MdAttributes } from './posts/[postId]/page'; | ||
import { PostCardProps } from './components/PostCard'; | ||
import { redirect } from 'next/navigation'; | ||
import { Metadata } from 'next'; | ||
|
||
const getPosts = async () => { | ||
const postNames = (await readdir(resolve(process.cwd(), 'src/posts'))).map( | ||
(file) => file.split('.')[0], | ||
); | ||
const postPaths = postNames.map((postName) => | ||
resolve(process.cwd(), `src/posts/${postName}.md`), | ||
); | ||
|
||
const postsPromises = postPaths.map(async (postPath, index) => { | ||
const data = await readFile(postPath, 'utf-8'); | ||
const content = fm<MdAttributes>(data); | ||
const post: PostCardProps = { | ||
...content.attributes, | ||
id: postNames[index], | ||
}; | ||
return post; | ||
}); | ||
|
||
const posts = await Promise.all(postsPromises); | ||
posts.sort((a, b) => { | ||
// Desc order by createdAt | ||
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); | ||
}); | ||
return posts; | ||
}; | ||
|
||
export const metadata: Metadata = { | ||
metadataBase: new URL('https://shubidumdu.github.io/devlog/'), | ||
title: "Shubidumdu's Devlog", | ||
metadataBase: new URL('https://shubidumdu.github.io/'), | ||
title: 'Shubidumdu', | ||
description: | ||
'Shubidumdu의 개발 블로그입니다. 개발 중 마주친 문제 및 그에 대한 해결과, 어떤 것의 구현에 대한 과정을 기록합니다.', | ||
'레트로, 신스팝, 디스코, 호러 따위를 좋아하는 프론트엔드 개발자 Shubidumdu입니다.', | ||
authors: [ | ||
{ | ||
name: 'Shubidumdu', | ||
url: 'https://github.com/Shubidumdu', | ||
}, | ||
], | ||
colorScheme: 'light', | ||
keywords: ['Shubidumdu', 'Devlog', 'Blog', '개발 블로그', '개발', '블로그'], | ||
keywords: ['Shubidumdu', 'Frontend', 'Developer'], | ||
openGraph: { | ||
title: "Shubidumdu's Devlog", | ||
title: 'Shubidumdu', | ||
description: | ||
'Shubidumdu의 개발 블로그입니다. 개발 중 마주친 문제 및 그에 대한 해결과, 어떤 것의 구현에 대한 과정을 기록합니다.', | ||
'레트로, 신스팝, 디스코, 호러 따위를 좋아하는 프론트엔드 개발자 Shubidumdu입니다.', | ||
images: './ogImage.png', | ||
}, | ||
}; | ||
|
||
export default async function Home() { | ||
const posts = await getPosts(); | ||
|
||
return ( | ||
<> | ||
<TopBar /> | ||
<main className="container font-mono my-0 mx-auto mt-16 mb-32"> | ||
<div> | ||
<PostCardList posts={posts} /> | ||
</div> | ||
</main> | ||
</> | ||
); | ||
redirect('/posts'); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import PostCardList from '../components/PostCardList'; | ||
import TopBar from '../components/TopBar'; | ||
import { resolve } from 'path'; | ||
import { readFile, readdir } from 'fs/promises'; | ||
import fm from 'front-matter'; | ||
import { MdAttributes } from '../posts/[postId]/page'; | ||
import { PostCardProps } from '../components/PostCard'; | ||
import { Metadata } from 'next'; | ||
import Background from '../components/Background'; | ||
|
||
const getPosts = async () => { | ||
const postNames = (await readdir(resolve(process.cwd(), 'src/posts'))).map( | ||
(file) => file.split('.')[0], | ||
); | ||
const postPaths = postNames.map((postName) => | ||
resolve(process.cwd(), `src/posts/${postName}.md`), | ||
); | ||
|
||
const postsPromises = postPaths.map(async (postPath, index) => { | ||
const data = await readFile(postPath, 'utf-8'); | ||
const content = fm<MdAttributes>(data); | ||
const post: PostCardProps = { | ||
...content.attributes, | ||
id: postNames[index], | ||
}; | ||
return post; | ||
}); | ||
|
||
const posts = await Promise.all(postsPromises); | ||
posts.sort((a, b) => { | ||
// Desc order by createdAt | ||
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); | ||
}); | ||
return posts; | ||
}; | ||
|
||
export const metadata: Metadata = { | ||
metadataBase: new URL('https://shubidumdu.github.io/devlog/'), | ||
title: "Shubidumdu's Posts", | ||
description: | ||
'개발 중 마주친 문제 및 그에 대한 해결과, 어떤 것의 구현에 대한 과정을 기록합니다.', | ||
authors: [ | ||
{ | ||
name: 'Shubidumdu', | ||
url: 'https://github.com/Shubidumdu', | ||
}, | ||
], | ||
colorScheme: 'light', | ||
keywords: ['Shubidumdu', 'Devlog', 'Blog', '개발 블로그', '개발', '블로그'], | ||
openGraph: { | ||
title: "Shubidumdu's Posts", | ||
description: | ||
'개발 중 마주친 문제 및 그에 대한 해결과, 어떤 것의 구현에 대한 과정을 기록합니다.', | ||
images: './ogImage.png', | ||
}, | ||
}; | ||
|
||
export default async function Home() { | ||
const posts = await getPosts(); | ||
|
||
return ( | ||
<> | ||
<TopBar /> | ||
<Background /> | ||
<main className="container font-mono my-0 mx-auto mt-16 mb-32"> | ||
<div> | ||
<PostCardList posts={posts} /> | ||
</div> | ||
</main> | ||
</> | ||
); | ||
} |