diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-03 17:53:30 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-03 17:53:30 +0800 |
commit | e2a6d73b940bd2a222747f777efc37c3b04b1d16 (patch) | |
tree | 784dc0f20336a39ce4d0709a8ccb778a5e248b83 | |
parent | HTTP: Ref type query errors should be 400, not 500 (diff) | |
download | forge-e2a6d73b940bd2a222747f777efc37c3b04b1d16.tar.gz forge-e2a6d73b940bd2a222747f777efc37c3b04b1d16.tar.zst forge-e2a6d73b940bd2a222747f777efc37c3b04b1d16.zip |
HTML: Use the proper repo_url_root in tree/rawtreev0.1.12
-rw-r--r-- | http_server.go | 7 | ||||
-rw-r--r-- | templates/repo_raw_dir.tmpl | 14 | ||||
-rw-r--r-- | templates/repo_tree_dir.tmpl | 14 |
3 files changed, 21 insertions, 14 deletions
diff --git a/http_server.go b/http_server.go index 722ac81..0a474cc 100644 --- a/http_server.go +++ b/http_server.go @@ -6,6 +6,7 @@ package main import ( "errors" "net/http" + "net/url" "strconv" "strings" @@ -184,6 +185,12 @@ func (router *forgeHTTPRouter) ServeHTTP(writer http.ResponseWriter, request *ht return } + repoURLRoot := "/" + for _, part := range segments[:sepIndex+3] { + repoURLRoot = repoURLRoot + url.PathEscape(part) + "/" + } + params["repo_url_root"] = repoURLRoot + if len(segments) == sepIndex+3 { if redirectDir(writer, request) { return diff --git a/templates/repo_raw_dir.tmpl b/templates/repo_raw_dir.tmpl index c0df8fd..4072326 100644 --- a/templates/repo_raw_dir.tmpl +++ b/templates/repo_raw_dir.tmpl @@ -16,25 +16,25 @@ <h2>{{- .repo_name -}}</h2> <ul class="nav-tabs-standalone"> <li class="nav-item"> - <a class="nav-link" href="../{{- template "ref_query" $root -}}">Summary</a> + <a class="nav-link" href="{{- .repo_url_root -}}{{- template "ref_query" $root -}}">Summary</a> </li> <li class="nav-item"> - <a class="nav-link active" href="../tree/{{- template "ref_query" $root -}}">Tree</a> + <a class="nav-link active" href="{{- .repo_url_root -}}tree/{{- template "ref_query" $root -}}">Tree</a> </li> <li class="nav-item"> - <a class="nav-link" href="../log/{{- template "ref_query" $root -}}">Log</a> + <a class="nav-link" href="{{- .repo_url_root -}}log/{{- template "ref_query" $root -}}">Log</a> </li> <li class="nav-item"> - <a class="nav-link" href="../branches/">Branches</a> + <a class="nav-link" href="{{- .repo_url_root -}}branches/">Branches</a> </li> <li class="nav-item"> - <a class="nav-link" href="../tags/">Tags</a> + <a class="nav-link" href="{{- .repo_url_root -}}tags/">Tags</a> </li> <li class="nav-item"> - <a class="nav-link" href="../contrib/">Merge requests</a> + <a class="nav-link" href="{{- .repo_url_root -}}contrib/">Merge requests</a> </li> <li class="nav-item"> - <a class="nav-link" href="../settings/">Settings</a> + <a class="nav-link" href="{{- .repo_url_root -}}settings/">Settings</a> </li> </ul> </div> diff --git a/templates/repo_tree_dir.tmpl b/templates/repo_tree_dir.tmpl index 3f43064..c528fee 100644 --- a/templates/repo_tree_dir.tmpl +++ b/templates/repo_tree_dir.tmpl @@ -16,25 +16,25 @@ <h2>{{- .repo_name -}}</h2> <ul class="nav-tabs-standalone"> <li class="nav-item"> - <a class="nav-link" href="../{{- template "ref_query" $root -}}">Summary</a> + <a class="nav-link" href="{{- .repo_url_root -}}{{- template "ref_query" $root -}}">Summary</a> </li> <li class="nav-item"> - <a class="nav-link active" href="../tree/{{- template "ref_query" $root -}}">Tree</a> + <a class="nav-link active" href="{{- .repo_url_root -}}tree/{{- template "ref_query" $root -}}">Tree</a> </li> <li class="nav-item"> - <a class="nav-link" href="../log/{{- template "ref_query" $root -}}">Log</a> + <a class="nav-link" href="{{- .repo_url_root -}}log/{{- template "ref_query" $root -}}">Log</a> </li> <li class="nav-item"> - <a class="nav-link" href="../branches/">Branches</a> + <a class="nav-link" href="{{- .repo_url_root -}}branches/">Branches</a> </li> <li class="nav-item"> - <a class="nav-link" href="../tags/">Tags</a> + <a class="nav-link" href="{{- .repo_url_root -}}tags/">Tags</a> </li> <li class="nav-item"> - <a class="nav-link" href="../contrib/">Merge requests</a> + <a class="nav-link" href="{{- .repo_url_root -}}contrib/">Merge requests</a> </li> <li class="nav-item"> - <a class="nav-link" href="../settings/">Settings</a> + <a class="nav-link" href="{{- .repo_url_root -}}settings/">Settings</a> </li> </ul> </div> |