blob: 953557ac6c98edf73bbab9226ad9328cf81a6a6a (
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"
"path/filepath"
"os"
"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
}
}
|