From e6bf5f1df4615e2600ae713755665df09511cd06 Mon Sep 17 00:00:00 2001 From: movsb Date: Thu, 12 Dec 2024 23:55:26 +0800 Subject: [PATCH] fix dir --- modules/utils/dir/dir.go | 19 ++++++++++++------- service/modules/renderers/friends/friends.go | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/utils/dir/dir.go b/modules/utils/dir/dir.go index 4528fce0..ee4ed852 100644 --- a/modules/utils/dir/dir.go +++ b/modules/utils/dir/dir.go @@ -1,6 +1,7 @@ package dir import ( + "log" "os" "path/filepath" "runtime" @@ -16,6 +17,7 @@ func init() { panic(err) } Root = rootDir + log.Println(`WorkingDir:`, rootDir) } type Dir string @@ -25,6 +27,15 @@ func (d Dir) Join(components ...string) string { } func SourceRelativeDir() Dir { + s := strings.TrimPrefix(string(SourceAbsoluteDir()), Root) + s = strings.TrimPrefix(s, "/") + if s == "" { + s = "." + } + return Dir(s) +} + +func SourceAbsoluteDir() Dir { _, file, _, ok := runtime.Caller(1) if !ok { panic(`无法获取路径。`) @@ -32,11 +43,5 @@ func SourceRelativeDir() Dir { if Root == "" { panic(`没有设置根目录。`) } - dir := filepath.Dir(file) - s := strings.TrimPrefix(dir, Root) - s = strings.TrimPrefix(s, "/") - if s == "" { - s = "." - } - return Dir(s) + return Dir(filepath.Dir(file)) } diff --git a/service/modules/renderers/friends/friends.go b/service/modules/renderers/friends/friends.go index aa180e27..bacc3174 100644 --- a/service/modules/renderers/friends/friends.go +++ b/service/modules/renderers/friends/friends.go @@ -30,7 +30,7 @@ func init() { string(utils.Must1(_root.ReadFile(`style.css`))), }, } - sass.WatchDefaultAsync(string(dir.SourceRelativeDir())) + sass.WatchDefaultAsync(string(dir.SourceAbsoluteDir())) } type Friends struct {