Update config.ts
This commit is contained in:
1 parent
d3365ab77a
commit
694f26fe0e
1 file changed
+6
-11
@@ -1,23 +1,18 @@
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
import os from "os";
|
||||
|
||||
// 获取博客根目录
|
||||
// 优先级:BLOG_ROOT 环境变量 > Docker 挂载 /blog > 上级目录
|
||||
// 优先级:BLOG_ROOT 环境变量 > Docker 容器检测 > 上级目录
|
||||
function getBlogRoot(): string {
|
||||
// 1. 环境变量
|
||||
// 1. 环境变量(非 Docker 部署时使用)
|
||||
const envRoot = process.env.BLOG_ROOT;
|
||||
if (envRoot && envRoot.trim() && envRoot !== "undefined") {
|
||||
const resolved = path.resolve(envRoot);
|
||||
if (fs.existsSync(path.join(resolved, "content"))) {
|
||||
return resolved;
|
||||
}
|
||||
return path.resolve(envRoot);
|
||||
}
|
||||
|
||||
// 2. Docker 挂载检测
|
||||
const dockerPath = "/blog";
|
||||
if (fs.existsSync(path.join(dockerPath, "content"))) {
|
||||
return dockerPath;
|
||||
// 2. Docker 容器检测:cwd 为 /app 时,博客挂载在 /blog
|
||||
if (process.cwd() === "/app") {
|
||||
return "/blog";
|
||||
}
|
||||
|
||||
// 3. 回退到上级目录
|
||||
|
||||
Reference in new issue
Block a user