/
repository.go
67 lines (60 loc) · 1.24 KB
/
repository.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
55
56
57
58
59
60
61
62
63
64
65
66
67
package sisho
import (
"github.com/gophergala2016/sisho/util"
"mime"
"os"
"path/filepath"
"regexp"
"strings"
)
func (s *Sisho) walkRepo() error {
// * walk repo and generate constitution of repo.
err := filepath.Walk(s.tmpDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
isGitDir, isGitDirErr := regexp.MatchString(s.tmpDir+"/.git/", path)
if isGitDirErr != nil {
return err
}
if isGitDir {
return nil
}
tmp := strings.Split(path, "/")
name := tmp[len(tmp)-1]
ext := filepath.Ext(path)
r := regexp.MustCompile(s.tmpDir + "/")
if util.IsBinary(ext) {
a := ContentAsset{
Content: Content{
path: path,
relativePath: r.ReplaceAllString(path, ""),
name: name,
contentType: mime.TypeByExtension(ext),
},
ext: ext,
}
s.assets = append(s.assets, a)
return nil
}
c := Code{
Content: Content{
path: path,
relativePath: r.ReplaceAllString(path, ""),
name: name,
contentType: mime.TypeByExtension(ext),
},
Title: "",
TextLines: []string{},
}
s.contents = append(s.contents, c)
return nil
})
if err == nil {
return err
}
return nil
}