Skip to content

perry2008084/sharemdc

Repository files navigation

ShareMDC

Share AI content and Markdown with one click.

License Node.js Express

✨ Features

🎨 Editor Features

  • Real-time Preview - See your Markdown rendered instantly as you type
  • One-Click Sharing - Generate short links and share content effortlessly
  • Content Persistence - SQLite database stores your content for later access

🌟 User Experience

  • Responsive Design - Perfectly adapted for desktop and mobile devices
  • Dark Mode - Toggle between light and dark themes with one click
  • Touch Optimized - Double-tap preview area to zoom in/out
  • Social Sharing - Share to WeChat, QQ, Weibo, and Twitter with one click

πŸ”’ Security

  • XSS Protection - DOMPurify sanitizes all HTML output
  • Input Validation - Strict content validation

🌐 Live Demo

Try ShareMDC at: https://www.sharemdc.com

πŸ“Έ Preview

Editor Page

  • Left side: Markdown editing area
  • Right side: Real-time preview
  • Top: Share button

Share Page

  • Rendered Markdown content
  • Share timestamp
  • Social media sharing buttons

πŸš€ Quick Start

Prerequisites

  • Node.js >= 18.0
  • npm >= 9.0

Installation

# Clone the repository
git clone https://github.com/perry2008084/sharemdc.git
cd sharemdc

# Install dependencies
npm install

# Start development server
npm run dev

# Start production server
npm start

Configuration

# Set port (default: 3000)
export PORT=8080

# Set database path (default: ./data/share.db)
export DB_PATH=/path/to/database.db

# Set Microsoft Clarity ID for analytics (optional)
# If not set, Clarity will be disabled
export CLARITY_ID=your_clarity_project_id

🚒 Self-Hosting / Deployment

ShareMDC is open source (MIT licensed) and can be self-hosted on any Node.js-compatible platform.

Quick Deploy with PM2

# Install PM2 globally
npm install -g pm2

# Start the service
pm2 start server.js --name sharemdc

# Set up auto-restart on system boot
pm2 startup
pm2 save

Deploy with Docker

# Build the image
docker build -t sharemdc .

# Run the container
docker run -p 3000:3000 -v ./data:/app/data sharemdc

Deploy with Nginx Reverse Proxy

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

HTTPS Configuration (Recommended)

For production, use Nginx with Let's Encrypt:

server {
    listen 443 ssl;
    server_name your-domain.com;

    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;

    location / {
        proxy_pass http://localhost:3000;
    }
}

πŸ“ Project Structure

sharemdc/
β”œβ”€β”€ public/              # Static files
β”‚   β”œβ”€β”€ index.html       # Editor page
β”‚   β”œβ”€β”€ share.html       # Share page
β”‚   β”œβ”€β”€ app.js          # Editor scripts
β”‚   β”œβ”€β”€ share.js        # Share page scripts
β”‚   └── styles.css      # Stylesheet
β”œβ”€β”€ data/               # Database directory
β”‚   └── share.db       # SQLite database
β”œβ”€β”€ server.js           # Express server
β”œβ”€β”€ package.json        # Project configuration
β”œβ”€β”€ .gitignore         # Git ignore rules
β”œβ”€β”€ design.md          # Design documentation
β”œβ”€β”€ usage.md           # Usage guide
└── LICENSE            # MIT License

πŸ”Œ API Reference

POST /api/share

Generate a share link

Request:

{
  "content": "# Hello World\n\nThis is a test."
}

Response:

{
  "id": "abc123xyz",
  "url": "/s/abc123xyz"
}

POST /api/preview

Preview Markdown content

Request:

{
  "content": "# Hello World"
}

Response:

{
  "html": "<h1>Hello World</h1>"
}

GET /api/share/:id

Retrieve shared content

Response:

{
  "content": "# Hello World",
  "createdAt": 1739918400000
}

GET /health

Health check

Response:

{
  "ok": true
}

πŸ› οΈ Tech Stack

Technology Version Purpose
Node.js 22.22.0 Runtime
Express 5.2.1 Web Framework
SQLite 3.x Database
better-sqlite3 12.6.2 SQLite Driver
marked 17.0.2 Markdown Parser
DOMPurify 3.3.1 XSS Protection
jsdom 28.1.0 DOM Simulation
nanoid 5.1.6 ID Generator

🎨 Design Philosophy

Responsive Layout

  • Desktop: Split layout (editor + preview)
  • Mobile: Single layout with touch gestures

Theme System

  • CSS variables for color management
  • localStorage persists theme preference
  • One-click light/dark mode toggle

Performance Optimization

  • Static file caching
  • Code splitting
  • Lazy loading

πŸ“± Mobile Features

Touch Gestures

  • Double-tap preview area - Zoom in/out font size
  • Touch targets - Minimum 44px, follows Apple guidelines

Responsive Typography

  • Desktop: Base font 16px
  • Mobile: Base font 14px
  • Code blocks: 12px

Social Sharing

  • WeChat: Copy link to clipboard
  • QQ: QQ share component
  • Weibo: Weibo share API
  • Twitter: Twitter share API

πŸ” Security

XSS Protection

Sanitize all HTML with DOMPurify:

const clean = DOMPurify.sanitize(raw);

Input Validation

  • Check if content is empty
  • Limit content size (max 1MB)
  • Validate ID format (10 characters)

πŸ“Š Performance

Load Times

  • First load: < 500ms
  • Real-time preview: < 50ms
  • Share generation: < 100ms

Resource Usage

  • Memory: ~60 MB (Node.js)
  • CPU: < 1% (idle)
  • Disk: < 10 MB (database + files)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Workflow

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style

  • Use 2 spaces for indentation
  • Follow ESLint configuration
  • Use Conventional Commits for commit messages

πŸ“ License

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

πŸ”§ Self-Hosting Configuration

When self-hosting ShareMDC, you may want to customize the following:

SEO and Social Sharing

The default HTML files include placeholder URLs (sharemdc.com) for Open Graph and Twitter meta tags. For production self-hosting, you should:

  1. Update public/index.html and public/share.html
  2. Replace sharemdc.com with your own domain
  3. Update the og:image and twitter:image URLs if hosting your own preview images

Example meta tag to update:

<meta property="og:url" content="https://your-domain.com/" />
<meta property="og:image" content="https://your-domain.com/og-image.png" />

Analytics

ShareMDC supports Microsoft Clarity analytics (optional). To enable:

  1. Create a project at clarity.microsoft.com
  2. Set the CLARITY_ID environment variable with your project ID
  3. If not set, Clarity will be completely disabled
export CLARITY_ID=your_clarity_project_id
npm start

πŸ‘¨β€πŸ’» Author

perry2008084

πŸ™ Acknowledgments

πŸ“§ Troubleshooting

Database Errors

If you encounter SQLite errors:

# Check database file permissions
ls -la data/

# Fix permissions
chmod 600 data/share.db
chmod 700 data/

Port Already in Use

# Find process using the port
lsof -i :3000

# Kill the process
kill -9 <PID>

PM2 Startup Issues

# Reset PM2
pm2 delete all
pm2 start server.js --name sharemdc

πŸ“ž Support

For questions or suggestions, please:


⭐ If this project helps you, please give it a Star!

About

Share AI content and Markdown with one click.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors