#!/bin/bash # Write Server 快速启动脚本 # 适用于开发和测试环境 set -e echo "===================================" echo " Write Server 快速启动" echo "===================================" # 检查 Node.js if ! command -v node &> /dev/null; then echo "错误: Node.js 未安装" echo "请先运行: ./scripts/install.sh" exit 1 fi # 检查 .env 文件 if [ ! -f .env ]; then echo "创建 .env 文件..." cp .env.example .env echo "" echo "请编辑 .env 文件配置 BLOG_ROOT:" echo " BLOG_ROOT=/path/to/your/hugo/blog" echo "" read -p "按 Enter 继续..." fi # 加载环境变量 source .env # 检查 BLOG_ROOT if [ -z "$BLOG_ROOT" ]; then echo "错误: BLOG_ROOT 未配置" echo "请编辑 .env 文件设置 BLOG_ROOT" exit 1 fi # 检查博客目录 if [ ! -d "$BLOG_ROOT" ]; then echo "错误: 博客目录不存在: $BLOG_ROOT" exit 1 fi # 检查 content/posts 目录 if [ ! -d "$BLOG_ROOT/content/posts" ]; then echo "警告: content/posts 目录不存在" echo "创建目录..." mkdir -p "$BLOG_ROOT/content/posts" fi # 检查依赖 echo "检查依赖..." if [ ! -d "node_modules" ]; then echo "安装依赖..." npm install fi # 检查是否已构建 if [ ! -d ".next" ]; then echo "构建项目..." npm run build fi # 创建必要的目录 mkdir -p logs backups recycle # 启动开发服务器 echo "" echo "启动开发服务器..." echo "" echo "服务地址: http://localhost:${PORT:-8016}" echo "博客目录: $BLOG_ROOT" echo "" echo "按 Ctrl+C 停止服务" echo "" npm run dev