1package gitweb
2
3import (
4 "io"
5 "path/filepath"
6 "regexp"
7 "strings"
8
9 "github.com/go-git/go-git/v5/plumbing"
10 "github.com/go-git/go-git/v5/plumbing/hash"
11)
12
13var readmeRegex = regexp.MustCompile(`README|(README\.[a-zA-Z0-9]+)`)
14
15func isReadme(fp string) bool {
16 name := filepath.Base(fp)
17 return readmeRegex.MatchString(name)
18}
19
20func readHashFile(r io.Reader) (plumbing.Hash, error) {
21 var hashData = make([]byte, hash.HexSize)
22 _, err := r.Read(hashData)
23 if err != nil {
24 return plumbing.Hash{}, err
25 }
26
27 // TODO: Consider building our own hex decoder?
28 return plumbing.NewHash(string(hashData)), nil
29}
30
31func repoTitle(path string) string {
32 title := filepath.Base(path)
33 ext := strings.LastIndex(title, ".git")
34 if ext > 0 {
35 title = title[0:ext]
36 }
37
38 return title
39}