all repos — legit @ cb188bedc29888a8f2ace1e1f9ad02496bb61033

web frontend for git

found a safer way to do it
Marco Andronaco andronacomarco@gmail.com
Thu, 13 Jun 2024 23:25:58 +0200
commit

cb188bedc29888a8f2ace1e1f9ad02496bb61033

parent

c14c33b9166614e77aaca735ca3d0eacf8c81a61

5 files changed, 24 insertions(+), 15 deletions(-)

jump to
M git/git.gogit/git.go

@@ -34,10 +34,7 @@ var err error

g := GitRepo{} g.r, err = git.PlainOpen(path) if err != nil { - g.r, err = git.PlainOpen(path + ".git") - if err != nil { - return nil, fmt.Errorf("opening %s: %w", path, err) - } + return nil, fmt.Errorf("opening %s: %w", path, err) } if ref == "" {
M routes/routes.goroutes/routes.go

@@ -31,8 +31,8 @@ return

} type info struct { - Name, Desc, Idle string - d time.Time + DisplayName, Name, Desc, Idle string + d time.Time } infos := []info{}

@@ -57,17 +57,15 @@ return

} name := dir.Name() - if name[len(name)-4:] == ".git" { - name = name[:len(name)-4] - } desc := getDescription(path) infos = append(infos, info{ - Name: name, - Desc: desc, - Idle: humanize.Time(c.Author.When), - d: c.Author.When, + DisplayName: getDisplayName(name), + Name: name, + Desc: desc, + Idle: humanize.Time(c.Author.When), + d: c.Author.When, }) }

@@ -152,6 +150,7 @@ }

data := make(map[string]any) data["name"] = name + data["displayname"] = getDisplayName(name) data["ref"] = mainBranch data["readme"] = readmeContent data["commits"] = commits

@@ -194,6 +193,7 @@ }

data := make(map[string]any) data["name"] = name + data["displayname"] = getDisplayName(name) data["ref"] = ref data["parent"] = treePath data["desc"] = getDescription(path)

@@ -228,6 +228,7 @@

contents, err := gr.FileContent(treePath) data := make(map[string]any) data["name"] = name + data["displayname"] = getDisplayName(name) data["ref"] = ref data["desc"] = getDescription(path) data["path"] = treePath

@@ -269,6 +270,7 @@ data := make(map[string]interface{})

data["commits"] = commits data["meta"] = d.c.Meta data["name"] = name + data["displayname"] = getDisplayName(name) data["ref"] = ref data["desc"] = getDescription(path) data["log"] = true

@@ -311,6 +313,7 @@ data["stat"] = diff.Stat

data["diff"] = diff.Diff data["meta"] = d.c.Meta data["name"] = name + data["displayname"] = getDisplayName(name) data["ref"] = ref data["desc"] = getDescription(path)

@@ -354,6 +357,7 @@ data := make(map[string]interface{})

data["meta"] = d.c.Meta data["name"] = name + data["displayname"] = getDisplayName(name) data["branches"] = branches data["tags"] = tags data["desc"] = getDescription(path)
M routes/util.goroutes/util.go

@@ -15,6 +15,14 @@ _, err := gr.FileContent("go.mod")

return err == nil } +func getDisplayName(name string) string { + l := len(name) - 4 + if name[l:] == ".git" { + name = name[:l] + } + return name +} + func getDescription(path string) (desc string) { db, err := os.ReadFile(filepath.Join(path, "description")) if err == nil {
M templates/index.htmltemplates/index.html

@@ -10,7 +10,7 @@ <body>

<main> <div class="index"> {{ range .info }} - <div class="index-name"><a href="/{{ .Name }}">{{ .Name }}</a></div> + <div class="index-name"><a href="/{{ .Name }}">{{ .DisplayName }}</a></div> <div class="desc">{{ .Desc }}</div> <div>{{ .Idle }}</div> {{ end }}
M templates/repo-header.htmltemplates/repo-header.html

@@ -2,7 +2,7 @@ {{ define "repoheader" }}

<header> <h2> <a href="/">all repos</a> - &mdash; {{ .name }} + &mdash; {{ .displayname }} {{ if .ref }} <span class="ref">@ {{ .ref }}</span> {{ end }}