-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.go
63 lines (57 loc) · 1.3 KB
/
files.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
package main
import (
"fmt"
"html/template"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
)
type FileOverview struct {
Mode string
Name string
Size string
Origin string
}
type FilesPage struct {
RepoData repoData
Files []FileOverview
}
func (f *FilesPage) renderPage(t *template.Template) {
debug("file page for '%v'", f.RepoData.Name)
output, err := os.Create(path.Join(args.OutputDir, f.RepoData.Name, "files.html"))
checkErr(err)
err = t.Execute(output, f)
checkErr(err)
}
func renderAllFilesPage(data repoData) {
t, err := template.ParseFS(htmlTemplates, "template.files.html", "template.partials.html")
checkErr(err)
files := make([]FileOverview, 0)
err = filepath.Walk(data.cloneDir(), func(filename string, info fs.FileInfo, err error) error {
if info.IsDir() && info.Name() == ".git" {
return filepath.SkipDir
}
if !info.IsDir() {
info, err := os.Stat(filename)
checkErr(err)
Name, _ := strings.CutPrefix(filename, data.cloneDir())
Name, _ = strings.CutPrefix(Name, "/")
tf := FileOverview{
Origin: filename,
Name: Name,
Mode: info.Mode().String(),
Size: fmt.Sprintf("%v", info.Size()),
}
files = append(files, tf)
}
return nil
})
checkErr(err)
index := FilesPage{
RepoData: data,
Files: files,
}
index.renderPage(t)
}