6fbdbaae by miraclesu

Refactor template

1 parent 5ccdaeb0
Showing 1 changed file with 23 additions and 22 deletions
...@@ -51,34 +51,35 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error { ...@@ -51,34 +51,35 @@ func (self *templatefile) visit(paths string, f os.FileInfo, err error) error {
51 if f == nil { 51 if f == nil {
52 return err 52 return err
53 } 53 }
54 if f.IsDir() { 54 if f.IsDir() || (f.Mode()&os.ModeSymlink) > 0 {
55 return nil 55 return nil
56 } else if (f.Mode() & os.ModeSymlink) > 0 { 56 }
57 if !HasTemplateEXt(paths) {
57 return nil 58 return nil
59 }
60
61 replace := strings.NewReplacer("\\", "/")
62 a := []byte(paths)
63 a = a[len([]byte(self.root)):]
64 subdir := path.Dir(strings.TrimLeft(replace.Replace(string(a)), "/"))
65 if _, ok := self.files[subdir]; ok {
66 self.files[subdir] = append(self.files[subdir], paths)
58 } else { 67 } else {
59 hasExt := false 68 m := make([]string, 1)
60 for _, v := range BeeTemplateExt { 69 m[0] = paths
61 if strings.HasSuffix(paths, v) { 70 self.files[subdir] = m
62 hasExt = true 71 }
63 break
64 }
65 }
66 if hasExt {
67 replace := strings.NewReplacer("\\", "/")
68 a := []byte(paths)
69 a = a[len([]byte(self.root)):]
70 subdir := path.Dir(strings.TrimLeft(replace.Replace(string(a)), "/"))
71 if _, ok := self.files[subdir]; ok {
72 self.files[subdir] = append(self.files[subdir], paths)
73 } else {
74 m := make([]string, 1)
75 m[0] = paths
76 self.files[subdir] = m
77 }
78 72
73 return nil
74 }
75
76 func HasTemplateEXt(paths string) bool {
77 for _, v := range BeeTemplateExt {
78 if strings.HasSuffix(paths, "."+v) {
79 return true
79 } 80 }
80 } 81 }
81 return nil 82 return false
82 } 83 }
83 84
84 func AddTemplateExt(ext string) { 85 func AddTemplateExt(ext string) {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!