Skip to content

Repository files navigation

Personal Knowledge Blog

A modern, lightweight blog built with React, TypeScript, and Vite. This blog replaces the previous Hexo-based setup with a custom solution that provides better control, modern development experience, and serves as a portfolio piece.

πŸš€ Features

  • Modern Stack: React + TypeScript + Vite for fast development and optimal performance
  • Markdown Support: Write posts in markdown with full GitHub Flavored Markdown support
  • Syntax Highlighting: Beautiful code highlighting using Prism
  • Search: Client-side search across all posts (title, content, tags)
  • Tag Filtering: Filter posts by tags
  • Featured Posts: Showcase section for recent posts
  • Mobile Responsive: Works great on all devices
  • Fast: Static site generation with optimal loading performance
  • GitHub Actions: Automated deployment to GitHub Pages

πŸ“ Project Structure

Blog/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── deploy.yml          # GitHub Actions deployment
β”œβ”€β”€ public/
β”‚   └── posts/                  # Markdown blog posts
β”‚       β”œβ”€β”€ post-1.md
β”‚       β”œβ”€β”€ post-2.md
β”‚       └── ...
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/             # React components
β”‚   β”‚   β”œβ”€β”€ PostList.tsx        # List of posts
β”‚   β”‚   β”œβ”€β”€ PostDetail.tsx      # Individual post view
β”‚   β”‚   β”œβ”€β”€ SearchBar.tsx       # Search functionality
β”‚   β”‚   β”œβ”€β”€ TagFilter.tsx       # Tag filtering
β”‚   β”‚   β”œβ”€β”€ FeaturedPosts.tsx   # Featured/recent posts
β”‚   β”‚   β”œβ”€β”€ Header.tsx          # Site header
β”‚   β”‚   └── Footer.tsx          # Site footer
β”‚   β”œβ”€β”€ pages/                  # Page components
β”‚   β”‚   β”œβ”€β”€ Home.tsx            # Home page
β”‚   β”‚   └── TagPage.tsx         # Tag-filtered page
β”‚   β”œβ”€β”€ utils/                  # Utility functions
β”‚   β”‚   β”œβ”€β”€ posts.ts            # Post loading/parsing
β”‚   β”‚   └── search.ts           # Search functionality
β”‚   β”œβ”€β”€ types/                  # TypeScript types
β”‚   β”‚   └── Post.ts             # Post interfaces
β”‚   β”œβ”€β”€ App.tsx                 # Main app component
β”‚   β”œβ”€β”€ App.css                 # App styles
β”‚   β”œβ”€β”€ main.tsx                # Entry point
β”‚   └── index.css               # Global styles
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ vite.config.ts
└── README.md

πŸ› οΈ Local Development

Prerequisites

  • Node.js 18+
  • npm or yarn

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/Blog.git
cd Blog
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev
  1. Open your browser to http://localhost:5173

Build for Production

npm run build

The built files will be in the dist/ directory.

Preview Production Build

npm run preview

✍️ Writing Blog Posts

Creating a New Post

  1. Create a new markdown file in public/posts/:
touch public/posts/my-new-post.md
  1. Add frontmatter at the top of the file:
---
title: "My New Post Title"
date: 2025-12-11 10:00:00
tags:
- JavaScript
- React
- TypeScript
featured: false
---

Your post content starts here...

Frontmatter Fields

  • title (required): The post title
  • date (required): Publication date in YYYY-MM-DD HH:mm:ss format
  • tags (optional): Array of tags
  • featured (optional): Set to true to feature this post

Markdown Features

  • Headers: Use #, ##, ###, etc.
  • Code blocks: Use triple backticks with language:
    ```typescript
    const greeting: string = "Hello, World!";
    ```
  • Lists: Both ordered and unordered
  • Links: [text](url)
  • Images: ![alt](url)
  • Tables: GitHub Flavored Markdown tables
  • Blockquotes: Use >

File Naming

Use kebab-case for filenames: my-awesome-post.md

The filename becomes the URL slug: /post/my-awesome-post

πŸš€ Deployment

GitHub Pages (Recommended)

This blog is configured to deploy automatically to GitHub Pages using GitHub Actions.

  1. Push your code to GitHub:
git add .
git commit -m "Initial commit"
git push origin main
  1. Enable GitHub Pages:

    • Go to your repository Settings
    • Navigate to Pages
    • Under "Build and deployment" β†’ Source, select "GitHub Actions"
  2. The blog will automatically deploy on every push to main

  3. Access your blog at: https://yourusername.github.io/Blog/

Custom Domain (Optional)

  1. Add a CNAME file to the public/ directory with your domain
  2. Configure your DNS settings to point to GitHub Pages
  3. Update the base in vite.config.ts to / instead of /Blog/

🎨 Customization

Styling

Edit src/App.css and src/index.css to customize the look and feel.

Key CSS variables in src/index.css:

--primary-color: #2563eb;
--text-color: #1f2937;
--bg-color: #ffffff;
--bg-secondary: #f9fafb;

Site Title

Update the site title in src/components/Header.tsx:

<h1>Your Blog Title</h1>

Base URL

If deploying to a different path, update vite.config.ts:

base: '/your-repo-name/',

And update App.tsx:

<Router basename="/your-repo-name">

πŸ”§ Tech Stack

  • React 18: UI library
  • TypeScript: Type safety
  • Vite: Build tool and dev server
  • React Router: Client-side routing
  • React Markdown: Markdown rendering
  • Prism: Syntax highlighting
  • Gray Matter: Frontmatter parsing

πŸ“ Migration from Hexo

This blog was migrated from Hexo to provide:

  • More control over features and styling
  • Modern development experience
  • Portfolio piece demonstrating React + TypeScript skills
  • Simpler deployment workflow (single repo vs. two)
  • Faster build times

See the migration blog post for details: [Coming soon]

πŸ› Troubleshooting

Posts not showing up

  • Verify the markdown files are in public/posts/
  • Check that frontmatter is valid YAML
  • Ensure date is in correct format: YYYY-MM-DD HH:mm:ss

Build fails

  • Clear node_modules and reinstall: rm -rf node_modules && npm install
  • Clear Vite cache: rm -rf node_modules/.vite

GitHub Pages 404

  • Verify base in vite.config.ts matches your repository name
  • Ensure GitHub Actions workflow has proper permissions
  • Check that GitHub Pages is enabled in repository settings

πŸ“„ License

MIT License - feel free to use this as a template for your own blog!

🀝 Contributing

This is a personal blog, but suggestions and improvements are welcome via issues or pull requests.


Built with ❀️ using React, TypeScript, and Vite

About

A new start, remember the past scribbles and start sharing new learnings again

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages