-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
54 lines (45 loc) · 1.02 KB
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package file
import (
"path/filepath"
"strings"
)
var (
assetLocations = []string{
"templates/customers",
"assets",
"config",
"layout",
"snippets",
"templates",
"locales",
"sections",
}
)
func pathInProject(root, filename string) bool {
return pathToProject(root, filename) != "" || isProjectDirectory(root, filename)
}
func isProjectDirectory(root, filename string) bool {
filename = strings.TrimPrefix(
filepath.ToSlash(filepath.Clean(filename)),
filepath.ToSlash(filepath.Clean(root)+"/"),
)
for _, dir := range assetLocations {
if dir == filename {
return true
}
}
return false
}
func pathToProject(root, filename string) string {
filename = strings.TrimPrefix(
filepath.ToSlash(filepath.Clean(filename)),
filepath.ToSlash(filepath.Clean(root)+"/"),
)
for _, dir := range assetLocations {
split := strings.SplitAfterN(filename, dir+"/", 2)
if len(split) > 1 && strings.HasPrefix(filename, dir+"/") {
return filepath.ToSlash(filepath.Join(dir, split[len(split)-1]))
}
}
return ""
}