summaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-17 21:33:04 +0530
committerLibravatar Anirudh Oppiliappan <x@icyphox.sh>2022-12-17 21:33:04 +0530
commit5091695e75b2db30b8926d8aa17164c84031bc77 (patch)
tree40cd73e213e935634229fdadb701badd939846fd /routes
parent4eaaf451295ce9b541769d1322543f2d982ef5b0 (diff)
downloadlegit-5091695e75b2db30b8926d8aa17164c84031bc77.tar.gz
legit-5091695e75b2db30b8926d8aa17164c84031bc77.tar.bz2
legit-5091695e75b2db30b8926d8aa17164c84031bc77.zip
templates: repo and log
Diffstat (limited to 'routes')
-rw-r--r--routes/routes.go35
-rw-r--r--routes/template.go2
2 files changed, 27 insertions, 10 deletions
diff --git a/routes/routes.go b/routes/routes.go
index 5a8d686..f52e86a 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -45,13 +45,7 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) {
return
}
- var desc string
- db, err := os.ReadFile(filepath.Join(path, "description"))
- if err == nil {
- desc = string(db)
- } else {
- desc = ""
- }
+ desc := getDescription(path)
infos = append(infos, info{
Name: dir.Name(),
@@ -83,7 +77,7 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
return
}
- files, err := gr.FileTree("")
+ commits, err := gr.Commits()
if err != nil {
d.Write500(w)
log.Println(err)
@@ -109,12 +103,25 @@ func (d *deps) RepoIndex(w http.ResponseWriter, r *http.Request) {
return
}
+ tpath := filepath.Join(d.c.Dirs.Templates, "*")
+ t := template.Must(template.ParseGlob(tpath))
+
+ if len(commits) >= 5 {
+ commits = commits[:5]
+ }
+
data := make(map[string]any)
data["name"] = name
data["ref"] = mainBranch
data["readme"] = readmeContent
+ data["commits"] = commits
+ data["desc"] = getDescription(path)
+
+ if err := t.ExecuteTemplate(w, "repo", data); err != nil {
+ log.Println(err)
+ return
+ }
- d.listFiles(files, data, w)
return
}
@@ -283,3 +290,13 @@ func (d *deps) ServeStatic(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, f)
}
+
+func getDescription(path string) (desc string) {
+ db, err := os.ReadFile(filepath.Join(path, "description"))
+ if err == nil {
+ desc = string(db)
+ } else {
+ desc = ""
+ }
+ return
+}
diff --git a/routes/template.go b/routes/template.go
index dc1ec35..6af5cfe 100644
--- a/routes/template.go
+++ b/routes/template.go
@@ -37,7 +37,7 @@ func (d *deps) listFiles(files []git.NiceTree, data map[string]any, w http.Respo
data["files"] = files
data["meta"] = d.c.Meta
- if err := t.ExecuteTemplate(w, "repo", data); err != nil {
+ if err := t.ExecuteTemplate(w, "tree", data); err != nil {
log.Println(err)
return
}