diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-10 13:46:50 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-10 13:46:50 +0800 |
commit | 0a5f821f78425d97c0797803e57aa2c2d6f982da (patch) | |
tree | 1047018864276e8b99c4375aa436ce1ff162789c /handle_category_index.go | |
parent | *.go: Linting (diff) | |
download | forge-0a5f821f78425d97c0797803e57aa2c2d6f982da.tar.gz forge-0a5f821f78425d97c0797803e57aa2c2d6f982da.tar.zst forge-0a5f821f78425d97c0797803e57aa2c2d6f982da.zip |
category_index: Add a repo index for each category
Diffstat (limited to 'handle_category_index.go')
-rw-r--r-- | handle_category_index.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/handle_category_index.go b/handle_category_index.go new file mode 100644 index 0000000..407d0e7 --- /dev/null +++ b/handle_category_index.go @@ -0,0 +1,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) + project_name := r.PathValue("project_name") + data["category_name"] = project_name + entries, err := os.ReadDir(filepath.Join(config.Git.Root, project_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 + } +} |