Skip to content

Commit

Permalink
fix dir
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Dec 12, 2024
1 parent e372a09 commit e6bf5f1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions modules/utils/dir/dir.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dir

import (
"log"
"os"
"path/filepath"
"runtime"
Expand All @@ -16,6 +17,7 @@ func init() {
panic(err)
}
Root = rootDir
log.Println(`WorkingDir:`, rootDir)
}

type Dir string
Expand All @@ -25,18 +27,21 @@ 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(`无法获取路径。`)
}
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))
}
2 changes: 1 addition & 1 deletion service/modules/renderers/friends/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e6bf5f1

Please sign in to comment.