2310
This commit is contained in:
1 parent
694f26fe0e
commit
c88b081fbb
2 files changed
+9
-19
No files matched your search
@@ -1,25 +1,10 @@
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
|
||||
// 获取博客根目录
|
||||
// 优先级:BLOG_ROOT 环境变量 > Docker 容器检测 > 上级目录
|
||||
function getBlogRoot(): string {
|
||||
// 1. 环境变量(非 Docker 部署时使用)
|
||||
const envRoot = process.env.BLOG_ROOT;
|
||||
if (envRoot && envRoot.trim() && envRoot !== "undefined") {
|
||||
return path.resolve(envRoot);
|
||||
}
|
||||
|
||||
// 2. Docker 容器检测:cwd 为 /app 时,博客挂载在 /blog
|
||||
if (process.cwd() === "/app") {
|
||||
return "/blog";
|
||||
}
|
||||
|
||||
// 3. 回退到上级目录
|
||||
return path.resolve(process.cwd(), "..");
|
||||
}
|
||||
|
||||
export const BLOG_ROOT = getBlogRoot();
|
||||
// 博客根目录
|
||||
// Docker 构建时 BLOG_ROOT=/blog 已被 Turbopack 内联
|
||||
// 本地开发时回退到上级目录
|
||||
export const BLOG_ROOT = process.env.BLOG_ROOT || path.resolve(process.cwd(), "..");
|
||||
|
||||
export const CONTENT_DIR = path.join(BLOG_ROOT, "content", "posts");
|
||||
export const STATIC_DIR = path.join(BLOG_ROOT, "static");
|
||||
|
||||
Reference in new issue
Block a user