blob: d81899a7e76d9ba2ca3d87bcf90c37e47d63b01e (
plain) (
blame)
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
|
package main
import (
"net/http"
"os"
"path/filepath"
"strings"
)
func handle_category_index(w http.ResponseWriter, r *http.Request) {
data := make(map[string]any)
category_name := r.PathValue("category_name")
data["category_name"] = category_name
entries, err := os.ReadDir(filepath.Join(config.Git.Root, category_name))
if err != nil {
_, _ = w.Write([]byte("Error listing repos: " + err.Error()))
return
}
repos := []string{}
for _, entry := range entries {
this_name := entry.Name()
if strings.HasSuffix(this_name, ".git") {
repos = append(repos, strings.TrimSuffix(this_name, ".git"))
}
}
data["repos"] = repos
err = templates.ExecuteTemplate(w, "category_index", data)
if err != nil {
_, _ = w.Write([]byte("Error rendering template: " + err.Error()))
return
}
}
|