-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit_list.go
51 lines (43 loc) · 996 Bytes
/
git_list.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
package main
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
)
func (g *GitBackend) PageExists(title string) bool {
g.mutex.RLock()
defer g.mutex.RUnlock()
filePath, _, err := g.resolvePath(g.dir, fmt.Sprintf("%s.md", title))
if err != nil {
return false
}
fi, err := os.Stat(filePath)
return err == nil && !fi.IsDir()
}
func (g *GitBackend) ListPages() ([]string, error) {
var pages []string
return pages, g.walkFiles(func(filePath, webPath string, info fs.DirEntry) error {
if filepath.Ext(filePath) == ".md" {
pages = append(pages, strings.TrimSuffix(webPath, ".md"))
}
return nil
})
}
func (g *GitBackend) ListFiles() ([]File, error) {
var files []File
return files, g.walkFiles(func(filePath, webPath string, info fs.DirEntry) error {
if filepath.Ext(filePath) != ".md" {
stat, err := os.Stat(filePath)
if err != nil {
return err
}
files = append(files, File{
Name: webPath,
Size: stat.Size(),
})
}
return nil
})
}