This commit is contained in:
Vaica committed 2026-06-21 22:56:07 +08:00
1 parent 66117d18fb
commit a5c7fa228e
2 files changed
+29 -8

No files matched your search

+5 -2
View File
@@ -8,5 +8,8 @@ mkdir -p /app/recycle/posts /app/recycle/meta /app/logs /app/backups
# 修复权限 # 修复权限
chown -R nextjs:nodejs /app/recycle /app/logs /app/backups chown -R nextjs:nodejs /app/recycle /app/logs /app/backups
# 以 nextjs 用户启动应用 # 调试:打印环境变量
exec su-exec nextjs "$@" echo "[entrypoint] BLOG_ROOT=$BLOG_ROOT"
# 以 nextjs 用户启动应用(保留环境变量)
exec su-exec nextjs env "$@"
+24 -6
View File
@@ -1,12 +1,30 @@
import path from "path"; import path from "path";
import fs from "fs";
import os from "os"; import os from "os";
// 支持环境变量配置 BLOG_ROOT(Linux 部署) // 获取博客根目录
// Docker 部署时,BLOG_ROOT 通过 Docker 环境变量传入,不要放在 .env 文件中 // 优先级:BLOG_ROOT 环境变量 > Docker 挂载 /blog > 上级目录
const envBlogRoot = process.env.BLOG_ROOT; function getBlogRoot(): string {
export const BLOG_ROOT = envBlogRoot && envBlogRoot.trim() // 1. 环境变量
? path.resolve(envBlogRoot) const envRoot = process.env.BLOG_ROOT;
: path.resolve(process.cwd(), ".."); if (envRoot && envRoot.trim() && envRoot !== "undefined") {
const resolved = path.resolve(envRoot);
if (fs.existsSync(path.join(resolved, "content"))) {
return resolved;
}
}
// 2. Docker 挂载检测
const dockerPath = "/blog";
if (fs.existsSync(path.join(dockerPath, "content"))) {
return dockerPath;
}
// 3. 回退到上级目录
return path.resolve(process.cwd(), "..");
}
export const BLOG_ROOT = getBlogRoot();
export const CONTENT_DIR = path.join(BLOG_ROOT, "content", "posts"); export const CONTENT_DIR = path.join(BLOG_ROOT, "content", "posts");
export const STATIC_DIR = path.join(BLOG_ROOT, "static"); export const STATIC_DIR = path.join(BLOG_ROOT, "static");