diff --git a/docusaurus.config.ts b/docusaurus.config.ts index f0db0c2..cd75b92 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -23,9 +23,11 @@ const config: Config = { locales: ['en'], }, + plugins: ['./src/plugins/recent-post'], + presets: [ [ - 'classic', + '@docusaurus/preset-classic', { docs: { sidebarPath: './sidebars.ts', @@ -42,6 +44,8 @@ const config: Config = { ], ], + customFields: {}, + themeConfig: { colorMode: { defaultMode: 'dark', diff --git a/package.json b/package.json index 16c9679..0a8ab0b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "blog", + "name": "wanderedtola.blog", "version": "0.0.0", "private": true, "scripts": { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 5b054bc..23e091e 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,10 +1,12 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; +import { usePluginData } from '@docusaurus/useGlobalData'; import Layout from '@theme/Layout'; import Heading from '@theme/Heading'; import Link from '@docusaurus/Link'; export default function Home() { const { siteConfig } = useDocusaurusContext(); + const { recentPosts }: any = usePluginData('docusaurus-plugin-recent-posts'); return ( @@ -23,7 +25,7 @@ export default function Home() {
공부하며 새로 알게된 정보들은 이곳에 정리하거나 
- 따로 모아 관리하고 + 따로 모아 관리하고
WebAssembly기반의 웹 생태계를 주목하고 있습니다.

@@ -31,10 +33,12 @@ export default function Home() {

Recent Posts

diff --git a/src/plugins/recent-post.js b/src/plugins/recent-post.js new file mode 100644 index 0000000..d560f27 --- /dev/null +++ b/src/plugins/recent-post.js @@ -0,0 +1,48 @@ +const fs = require('fs'); +const path = require('path'); +const matter = require('gray-matter'); + +async function createRecentPostsPlugin(context, options) { + return { + name: 'docusaurus-plugin-recent-posts', + + async loadContent() { + const blogDir = path.join(__dirname, '../../blog'); + const files = fs.readdirSync(blogDir); + + const posts = []; + + files.forEach((file) => { + const filePath = path.join(blogDir, file); + const stat = fs.statSync(filePath); + + if (stat.isDirectory()) { + const indexFilePath = path.join(filePath, 'index.md'); + if (fs.existsSync(indexFilePath)) { + const content = fs.readFileSync(indexFilePath, 'utf-8'); + const frontMatter = matter(content).data; + if (frontMatter.slug && frontMatter.title) { + const dateStr = file.split('-').slice(0, 3).join('-'); + + posts.push({ + slug: frontMatter.slug, + title: frontMatter.title, + date: dateStr, + }); + } + } + } + }); + posts.sort((a, b) => b.date - a.date); + + return posts.slice(0, 5); + }, + + async contentLoaded({ content, actions }) { + const { setGlobalData } = actions; + setGlobalData({ recentPosts: content }); + }, + }; +} + +module.exports = createRecentPostsPlugin;