diff --git a/build.js b/build.js index 00de931..0e94bee 100644 --- a/build.js +++ b/build.js @@ -14,15 +14,20 @@ years.forEach(year => { if (file.endsWith('.md')) { const fileName = file.replace('.md', ''); const parts = fileName.split('-'); - const date = parts.slice(0, 3).join('-'); + + const y = parts[0]; + const m = parts[1]; + const d = parts[2]; const slug = parts.slice(3).join('-'); allPosts.push({ - year, - date, + year: y, + month: m, + day: d, slug, originalName: fileName, - title: slug.replace(/-/g, ' ') + title: slug.replace(/-/g, ' '), + date: `${y}-${m}-${d}` }); } }); @@ -38,7 +43,7 @@ if (fs.existsSync(path.join(distDir, 'index.html'))) { fs.writeFileSync(path.join(distDir, 'posts.json'), postsData); allPosts.forEach(post => { - const targetDir = path.join(distDir, post.year); + const targetDir = path.join(distDir, post.year, post.month, post.day); if (!fs.existsSync(targetDir)) { fs.mkdirSync(targetDir, { recursive: true }); } diff --git a/src/App.jsx b/src/App.jsx index a55115d..676336b 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -22,7 +22,7 @@ export default function App() { .then(res => res.json()) .then(data => { setPosts(data); - + const pathClean = currentPath.replace(/\.html$/, ''); const parts = pathClean.split('/').filter(Boolean); @@ -31,9 +31,15 @@ export default function App() { return; } - if (parts.length === 2) { - const [year, slug] = parts; - const found = data.find(p => p.year === year && p.slug === slug); + if (parts.length === 4) { + const [year, month, day, slug] = parts; + + const found = data.find(p => + p.year === year && + p.month === month && + p.day === day && + p.slug === slug + ); if (found) { fetch(`/posts/${year}/${found.originalName}.md`) diff --git a/src/Home.jsx b/src/Home.jsx index e27028d..29fc441 100644 --- a/src/Home.jsx +++ b/src/Home.jsx @@ -17,14 +17,14 @@ export default function Home({ posts }) { {currentPosts.map(post => (