Update config.ts

This commit is contained in:
Vaica committed 2026-06-21 23:01:11 +08:00
1 parent a5c7fa228e
commit ef595cacbf
1 file changed
+6 -11
+6 -11
View File
@@ -1,23 +1,18 @@
import path from "path"; import path from "path";
import fs from "fs";
import os from "os"; import os from "os";
// 获取博客根目录 // 获取博客根目录
// 优先级:BLOG_ROOT 环境变量 > Docker 挂载 /blog > 上级目录 // 优先级:BLOG_ROOT 环境变量 > Docker 容器检测 > 上级目录
function getBlogRoot(): string { function getBlogRoot(): string {
// 1. 环境变量 // 1. 环境变量(非 Docker 部署时使用)
const envRoot = process.env.BLOG_ROOT; const envRoot = process.env.BLOG_ROOT;
if (envRoot && envRoot.trim() && envRoot !== "undefined") { if (envRoot && envRoot.trim() && envRoot !== "undefined") {
const resolved = path.resolve(envRoot); return path.resolve(envRoot);
if (fs.existsSync(path.join(resolved, "content"))) {
return resolved;
}
} }
// 2. Docker 挂载检测 // 2. Docker 容器检测:cwd 为 /app 时,博客挂载在 /blog
const dockerPath = "/blog"; if (process.cwd() === "/app") {
if (fs.existsSync(path.join(dockerPath, "content"))) { return "/blog";
return dockerPath;
} }
// 3. 回退到上级目录 // 3. 回退到上级目录