diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-10 13:47:32 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-10 13:47:32 +0800 |
commit | d486fd9322a3fe1cf514d9fcc80d8996d9f49979 (patch) | |
tree | b8e573d40effacf5b71bca5e020048b90e238b21 | |
parent | category_index: Add a repo index for each category (diff) | |
download | forge-d486fd9322a3fe1cf514d9fcc80d8996d9f49979.tar.gz forge-d486fd9322a3fe1cf514d9fcc80d8996d9f49979.tar.zst forge-d486fd9322a3fe1cf514d9fcc80d8996d9f49979.zip |
*: project -> category
-rw-r--r-- | handle_category_index.go | 6 | ||||
-rw-r--r-- | handle_repo_index.go | 6 | ||||
-rw-r--r-- | handle_repo_tree.go | 6 | ||||
-rw-r--r-- | main.go | 6 | ||||
-rw-r--r-- | templates/repo_index.html | 2 | ||||
-rw-r--r-- | templates/repo_tree_dir.html | 2 | ||||
-rw-r--r-- | templates/repo_tree_file.html | 2 |
7 files changed, 15 insertions, 15 deletions
diff --git a/handle_category_index.go b/handle_category_index.go index 407d0e7..953557a 100644 --- a/handle_category_index.go +++ b/handle_category_index.go @@ -9,9 +9,9 @@ import ( 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)) + 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 diff --git a/handle_repo_index.go b/handle_repo_index.go index 89aeba6..44ba481 100644 --- a/handle_repo_index.go +++ b/handle_repo_index.go @@ -15,9 +15,9 @@ import ( func handle_repo_index(w http.ResponseWriter, r *http.Request) { data := make(map[string]any) // TODO: Sanitize path values - project_name, repo_name := r.PathValue("project_name"), r.PathValue("repo_name") - data["project_name"], data["repo_name"] = project_name, repo_name - repo, err := git.PlainOpen(filepath.Join(config.Git.Root, project_name, repo_name+".git")) + category_name, repo_name := r.PathValue("category_name"), r.PathValue("repo_name") + data["category_name"], data["repo_name"] = category_name, repo_name + repo, err := git.PlainOpen(filepath.Join(config.Git.Root, category_name, repo_name+".git")) if err != nil { _, _ = w.Write([]byte("Error opening repo: " + err.Error())) return diff --git a/handle_repo_tree.go b/handle_repo_tree.go index 8b8630d..cc79202 100644 --- a/handle_repo_tree.go +++ b/handle_repo_tree.go @@ -16,9 +16,9 @@ import ( func handle_repo_tree(w http.ResponseWriter, r *http.Request) { data := make(map[string]any) // TODO: Sanitize path values - project_name, repo_name, path_spec := r.PathValue("project_name"), r.PathValue("repo_name"), strings.TrimSuffix(r.PathValue("rest"), "/") - data["project_name"], data["repo_name"], data["path_spec"] = project_name, repo_name, path_spec - repo, err := git.PlainOpen(filepath.Join(config.Git.Root, project_name, repo_name+".git")) + category_name, repo_name, path_spec := r.PathValue("category_name"), r.PathValue("repo_name"), strings.TrimSuffix(r.PathValue("rest"), "/") + data["category_name"], data["repo_name"], data["path_spec"] = category_name, repo_name, path_spec + repo, err := git.PlainOpen(filepath.Join(config.Git.Root, category_name, repo_name+".git")) if err != nil { _, _ = w.Write([]byte("Error opening repo: " + err.Error())) return @@ -32,9 +32,9 @@ func main() { } http.HandleFunc("/{$}", handle_index) - http.HandleFunc("/{project_name}/{$}", handle_category_index) - http.HandleFunc("/{project_name}/repos/{repo_name}/{$}", handle_repo_index) - http.HandleFunc("/{project_name}/repos/{repo_name}/tree/{ref}/{rest...}", handle_repo_tree) + http.HandleFunc("/{category_name}/{$}", handle_category_index) + http.HandleFunc("/{category_name}/repos/{repo_name}/{$}", handle_repo_index) + http.HandleFunc("/{category_name}/repos/{repo_name}/tree/{ref}/{rest...}", handle_repo_tree) listener, err := net.Listen(config.HTTP.Net, config.HTTP.Addr) if err != nil { diff --git a/templates/repo_index.html b/templates/repo_index.html index 13ac023..dc8d672 100644 --- a/templates/repo_index.html +++ b/templates/repo_index.html @@ -3,7 +3,7 @@ <html> <head> <link rel="stylesheet" href="/static/style.css" /> -<title>{{ .project_name }}/repos/{{ .repo_name }}</title> +<title>{{ .category_name }}/repos/{{ .repo_name }}</title> </head> <body class="repo-index"> <div class="padding-wrapper"> diff --git a/templates/repo_tree_dir.html b/templates/repo_tree_dir.html index 93fa830..aa96b5d 100644 --- a/templates/repo_tree_dir.html +++ b/templates/repo_tree_dir.html @@ -3,7 +3,7 @@ <html> <head> <link rel="stylesheet" href="/static/style.css" /> -<title>{{ .project_name }}/repos/{{ .repo_name }}/{{ .path_spec }}</title> +<title>{{ .category_name }}/repos/{{ .repo_name }}/{{ .path_spec }}</title> </head> <body class="repo-tree-dir"> <div class="padding-wrapper"> diff --git a/templates/repo_tree_file.html b/templates/repo_tree_file.html index 7cf335a..72bf42b 100644 --- a/templates/repo_tree_file.html +++ b/templates/repo_tree_file.html @@ -3,7 +3,7 @@ <html> <head> <link rel="stylesheet" href="/static/style.css" /> -<title>{{ .project_name }}/repos/{{ .repo_name }}/{{ .path_spec }}</title> +<title>{{ .category_name }}/repos/{{ .repo_name }}/{{ .path_spec }}</title> </head> <body class="repo-tree-file"> <p> |