增加 自定义导航栏模块

This commit is contained in:
2026-04-17 03:12:28 +08:00
parent 792f547dc3
commit ec508e6a32
18 changed files with 1274 additions and 653 deletions

View File

@@ -62,3 +62,24 @@ func GetRootDir() string {
return baseDir
}
// DisplayPath 返回适合日志展示的路径。
// 对项目根目录内的文件保留相对路径;其他路径退化为文件名,避免泄露绝对安装目录。
func DisplayPath(path string) string {
if path == "" {
return ""
}
cleanPath := filepath.Clean(path)
if !filepath.IsAbs(cleanPath) {
return cleanPath
}
rootDir := filepath.Clean(GetRootDir())
rel, err := filepath.Rel(rootDir, cleanPath)
if err == nil && rel != "." && rel != ".." && !strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
return rel
}
return filepath.Base(cleanPath)
}