diff --git a/package.json b/package.json index 45e41a2..9f6dbdc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "vite", "clean": "rm -rf dist", "prebuild": "bun run clean", - "build": "vite build && bun build.js", + "build": "vite build && bun post.config.js", "lint": "eslint .", "preview": "vite preview" }, diff --git a/build.js b/post.config.js similarity index 74% rename from build.js rename to post.config.js index c5f605b..cb7ce14 100644 --- a/build.js +++ b/post.config.js @@ -2,32 +2,34 @@ import fs from 'fs'; import path from 'path'; const postsDir = './public/posts'; -const distDir = './dist'; +const distDir = './dist'; const allPosts = []; -const years = fs.readdirSync(postsDir); +const years = fs.readdirSync(postsDir); years.forEach(year => { const yearPath = path.join(postsDir, year); + if (fs.lstatSync(yearPath).isDirectory()) { const files = fs.readdirSync(yearPath); + files.forEach(file => { if (file.endsWith('.md')) { const fileName = file.replace('.md', ''); - const parts = fileName.split('-'); + const parts = fileName.split('-'); - const y = parts[0]; - const m = parts[1]; - const d = parts[2]; + const y = parts[0]; + const m = parts[1]; + const d = parts[2]; const slug = parts.slice(3).join('-'); allPosts.push({ - year: y, - month: m, - day: d, + year : y, + month : m, + day : d, slug, - originalName: fileName, - title: slug.replace(/-/g, ' '), - date: `${y}-${m}-${d}` + originalName : fileName, + title : slug.replace(/-/g, ' '), + date : `${y}-${m}-${d}` }); } }); @@ -51,11 +53,13 @@ if (fs.existsSync(path.join(distDir, 'index.html'))) { allPosts.forEach(post => { const targetDir = path.join(distDir, post.year, post.month, post.day); + if (!fs.existsSync(targetDir)) { fs.mkdirSync(targetDir, { recursive: true }); } + fs.copyFileSync( - path.join(distDir, 'index.html'), + path.join(distDir , 'index.html'), path.join(targetDir, `${post.slug}.html`) ); }); diff --git a/src/App.jsx b/src/App.jsx index 4317260..1bdef22 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,10 +3,10 @@ import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'; -import Analytics from './Analytics'; -import NotFound from './NotFound'; -import Home from './Home'; -import './App.css'; +import Analytics from './components/Analytics'; +import NotFound from './pages/NotFound/NotFound'; +import Home from './pages/Home/Home'; +import './styles/App.css'; export default function App() { const [content, setContent] = useState(''); diff --git a/src/Analytics.jsx b/src/components/Analytics.jsx similarity index 95% rename from src/Analytics.jsx rename to src/components/Analytics.jsx index e2bea14..3f84caa 100644 --- a/src/Analytics.jsx +++ b/src/components/Analytics.jsx @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import siteConfig from './config.json'; +import siteConfig from '../data/config.json'; export default function Analytics() { const trackingId = siteConfig.analytics.trackingId; diff --git a/src/config.json b/src/data/config.json similarity index 100% rename from src/config.json rename to src/data/config.json diff --git a/src/main.jsx b/src/main.jsx index b9a1a6d..d91ba14 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -1,6 +1,6 @@ import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' -import './index.css' +import './styles/index.css' import App from './App.jsx' createRoot(document.getElementById('root')).render( diff --git a/src/Home.css b/src/pages/Home/Home.css similarity index 100% rename from src/Home.css rename to src/pages/Home/Home.css diff --git a/src/Home.jsx b/src/pages/Home/Home.jsx similarity index 100% rename from src/Home.jsx rename to src/pages/Home/Home.jsx diff --git a/src/NotFound.css b/src/pages/NotFound/NotFound.css similarity index 100% rename from src/NotFound.css rename to src/pages/NotFound/NotFound.css diff --git a/src/NotFound.jsx b/src/pages/NotFound/NotFound.jsx similarity index 89% rename from src/NotFound.jsx rename to src/pages/NotFound/NotFound.jsx index a569155..7761e90 100644 --- a/src/NotFound.jsx +++ b/src/pages/NotFound/NotFound.jsx @@ -1,10 +1,8 @@ -import Analytics from './Analytics'; import './NotFound.css'; export default function NotFound() { return ( <> -

404

Page Not Found

diff --git a/src/App.css b/src/styles/App.css similarity index 100% rename from src/App.css rename to src/styles/App.css diff --git a/src/index.css b/src/styles/index.css similarity index 100% rename from src/index.css rename to src/styles/index.css