support redirecting project alternative names

This commit is contained in:
mappu 2020-05-05 19:30:28 +12:00
parent 7045794c8e
commit 28e7e769b1
2 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,9 @@ BindTo="0.0.0.0:5656"
URL="https://gitea.com/"
Org="gitea"
[Redirect]
"old-project-name" = "new-project-name"
[Template]
AppName = "Teafolio"

View File

@ -21,6 +21,7 @@ type Config struct {
Gitea struct {
URL, Org string
}
Redirect map[string]string
Template struct {
AppName string
HomepageHeaderHTML string
@ -308,6 +309,13 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// Maybe it's a redirected project (alternative name)
if rename, ok := this.cfg.Redirect[repoName]; ok {
w.Header().Set(`Location`, `/`+url.PathEscape(rename))
w.WriteHeader(301)
return
}
this.Repopage(w, r, repoName)
} else if r.URL.Path == `/static/logo.png` {