A simple Vite + React + TypeScript blog frontend that renders Markdown-based blog posts stored in the src/blogs/
directory.
src/
├── blogs/
│ ├── blogIndex.ts # Maps slugs to markdown file paths
│ ├── demo/
│ │ └── demo.md # Example blog post
│ └── another-post/
│ └── index.md # Another blog post
├── pages/
│ ├── Home.tsx # Main blog listing page
│ └── BlogEntry.tsx # Dynamic blog page for each slug
├── App.tsx # Route definitions
# Install dependencies
yarn install
# Start dev server
yarn dev
# Open in browser
http://localhost:5173
To add a new blog post:
-
Create a folder in
src/blogs/
The folder name will be the blog's slug (URL path). -
Add a Markdown file inside
Name it however you like (e.g.,index.md
orslug.md
). -
Register the new post in
blogIndex.ts
Map the slug to the file path relative to theblogs
directory.
src/blogs/my-first-post/index.md
// blogIndex.ts
export const blogMap: Record<string, string> = {
demo: 'demo/demo.md',
'my-first-post': 'my-first-post/index.md',
};
- Access the post via browser:
http://localhost:5173/blog/my-first-post
-
Blog posts are loaded dynamically using
import.meta.glob
with support for nested folders:import.meta.glob('../blogs/**/*.md')
-
Markdown is rendered using
react-markdown
.