Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ blog Public

Personal portfolio and blogging website

License

st3inum/blog

Repository files navigation

MathBugs Blog

A modern blog built with Next.js 15, featuring mathematics content, programming tutorials, and more. This project includes PWA capabilities, RSS feed generation, and Docker support.

πŸš€ Features

  • Next.js 15 with Turbopack for fast development
  • TypeScript for type safety
  • Material-UI for modern UI components
  • PWA Support with service worker and offline capabilities
  • RSS Feed automatically generated from posts
  • Syntax Highlighting with Prism and Shiki
  • Math Rendering with KaTeX
  • Docker Support for containerized deployment
  • SEO Optimized with proper meta tags and structured data

πŸ“‹ Prerequisites

  • Node.js 22 or higher
  • npm 10 or higher
  • Docker (optional, for containerized deployment)

πŸ› οΈ Local Development Setup

1. Clone the Repository

git clone <repository-url>
cd blog

2. Switch to Node.js 22

If you're using nvm:

nvm use 22
# or install if not available
nvm install 22
nvm use 22

Verify your Node.js version:

node --version  # Should show v22.x.x
npm --version   # Should show v10.x.x or higher

3. Install Dependencies

npm install

4. Start Development Server

npm run dev

The application will be available at:

5. Available Scripts

# Development server with RSS generation
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Generate RSS feed only
npm run generate-rss

# Lint code
npm run lint

# Export static site
npm run export

🐳 Docker Development

Prerequisites

  1. Install Docker: Make sure Docker is installed and running

  2. Start Docker daemon:

    sudo systemctl start docker
    sudo systemctl enable docker  # Enable on boot
  3. Add user to docker group (optional, to avoid using sudo):

    sudo usermod -aG docker $USER
    # Log out and back in for changes to take effect

Using Docker Compose (Recommended)

  1. Build and run production container:

    docker compose up --build
  2. Run in background:

    docker compose up --build -d
  3. Development mode with hot reload:

    docker compose --profile dev up blog-dev --build
  4. View logs:

    docker compose logs -f
  5. Stop containers:

    docker compose down

Using Docker Commands Directly

  1. Build production image:

    docker build -t mathbugs-blog .
  2. Run production container:

    docker run -p 3000:3000 --name mathbugs-blog-container mathbugs-blog
  3. Build development image:

    docker build -f Dockerfile.dev -t mathbugs-blog-dev .
  4. Run development container with volume mounting:

    docker run -p 3001:3000 \
      -v $(pwd):/app \
      -v /app/node_modules \
      -v /app/.next \
      --name mathbugs-blog-dev-container \
      mathbugs-blog-dev

πŸš€ Deployment Options

1. Vercel (Recommended for Next.js)

  1. Install Vercel CLI:

    npm install -g vercel
  2. Deploy:

    vercel
  3. Production deployment:

    vercel --prod

2. Docker Production Deployment

  1. Build production image:

    docker build -t mathbugs-blog:latest .
  2. Run with environment variables:

    docker run -d \
      -p 3000:3000 \
      --name mathbugs-blog \
      --restart unless-stopped \
      -e NODE_ENV=production \
      mathbugs-blog:latest
  3. Using docker-compose for production:

    docker compose -f docker-compose.yml up -d

3. Traditional VPS/Server Deployment

  1. Build the application:

    npm run build
  2. Start with PM2 (process manager):

    npm install -g pm2
    pm2 start npm --name "mathbugs-blog" -- start
    pm2 save
    pm2 startup
  3. Using systemd service: Create /etc/systemd/system/mathbugs-blog.service:

    [Unit]
    Description=MathBugs Blog
    After=network.target
    
    [Service]
    Type=simple
    User=www-data
    WorkingDirectory=/path/to/blog
    ExecStart=/usr/bin/npm start
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target

    Enable and start:

    sudo systemctl enable mathbugs-blog
    sudo systemctl start mathbugs-blog

4. Static Export Deployment

For static hosting (GitHub Pages, Netlify, etc.):

  1. Update next.config.ts for static export:

    const nextConfig: NextConfig = {
      reactStrictMode: true,
      output: "export",
      images: {
        unoptimized: true,
      },
    };
  2. Build and export:

    npm run build
    npm run export
  3. Deploy the out/ directory to your static hosting provider.

πŸ”§ Configuration

Environment Variables

Create a .env.local file for local development:

# Optional: Disable Next.js telemetry
NEXT_TELEMETRY_DISABLED=1

# Add your custom environment variables here

Customization

  • Posts: Add markdown files to the posts/ directory
  • Styling: Modify CSS files in src/styles/
  • Components: Edit React components in src/components/
  • Configuration: Update next.config.ts for build settings

πŸ“ Project Structure

β”œβ”€β”€ public/              # Static assets
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”œβ”€β”€ pages/          # Next.js pages
β”‚   β”œβ”€β”€ styles/         # CSS styles
β”‚   └── lib/            # Utility functions
β”œβ”€β”€ posts/              # Blog posts (Markdown)
β”œβ”€β”€ scripts/            # Build scripts
β”œβ”€β”€ Dockerfile          # Production Docker image
β”œβ”€β”€ Dockerfile.dev      # Development Docker image
β”œβ”€β”€ docker-compose.yml  # Docker Compose configuration
└── next.config.ts      # Next.js configuration

πŸ› Troubleshooting

Common Issues

  1. Docker daemon not running:

    sudo systemctl start docker
  2. Permission denied for Docker:

    sudo usermod -aG docker $USER
    # Log out and back in
  3. Node.js version mismatch:

    nvm use 22
  4. Build failures:

    rm -rf node_modules package-lock.json
    npm install
  5. Port already in use:

    # Kill process on port 3000
    lsof -ti:3000 | xargs kill -9

Docker Compose Version Warning

If you see warnings about version being obsolete, remove the first line from docker-compose.yml:

# Remove this line:
version: '3.8'

# Keep this:
services:
  # ... rest of configuration

πŸ“ License

This project is licensed under the MIT License - see the LICENCE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“§ Support

For issues and questions, please open an issue on the GitHub repository.


Happy coding! πŸš€