mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-23 15:41:36 +00:00
Add [[wildcard]].index-repo-branch option (pages by default).
This commit is contained in:
@@ -13,6 +13,7 @@ metrics = "tcp/:3002"
|
||||
domain = "codeberg.page"
|
||||
clone-url = "https://codeberg.org/<user>/<project>.git"
|
||||
index-repos = ["<user>.codeberg.page", "pages"]
|
||||
index-repo-branch = "main"
|
||||
fallback-proxy-to = "https://codeberg.page"
|
||||
|
||||
[storage]
|
||||
|
||||
@@ -229,6 +229,7 @@ func authorizeWildcardMatchSite(r *http.Request, pattern *WildcardPattern) (*Aut
|
||||
|
||||
if userName, found := pattern.Matches(host); found {
|
||||
var repoURLs []string
|
||||
var branch string
|
||||
repoURLTemplate := pattern.CloneURL
|
||||
if projectName == ".index" {
|
||||
for _, indexRepoTemplate := range pattern.IndexRepos {
|
||||
@@ -238,16 +239,15 @@ func authorizeWildcardMatchSite(r *http.Request, pattern *WildcardPattern) (*Aut
|
||||
"project": indexRepo,
|
||||
}))
|
||||
}
|
||||
branch = pattern.IndexBranch
|
||||
} else {
|
||||
repoURLs = append(repoURLs, repoURLTemplate.ExecuteString(map[string]any{
|
||||
"user": userName,
|
||||
"project": projectName,
|
||||
}))
|
||||
branch = "pages"
|
||||
}
|
||||
return &Authorization{
|
||||
repoURLs: repoURLs,
|
||||
branch: "pages",
|
||||
}, nil
|
||||
return &Authorization{repoURLs, branch}, nil
|
||||
} else {
|
||||
return nil, AuthError{
|
||||
http.StatusUnauthorized,
|
||||
|
||||
@@ -55,6 +55,7 @@ type WildcardConfig struct {
|
||||
Domain string `toml:"domain"`
|
||||
CloneURL string `toml:"clone-url"`
|
||||
IndexRepos []string `toml:"index-repos" default:"[]"`
|
||||
IndexRepoBranch string `toml:"index-repo-branch" default:"pages"`
|
||||
FallbackProxyTo string `toml:"fallback-proxy-to"`
|
||||
FallbackInsecure bool `toml:"fallback-insecure"`
|
||||
}
|
||||
@@ -274,5 +275,11 @@ func Configure(tomlPath string) (config *Config, err error) {
|
||||
return nil
|
||||
})
|
||||
|
||||
// defaults for wildcards aren't set by `defaults.MustSet` call above because the structs
|
||||
// for them haven't been created yet
|
||||
for i := range config.Wildcard {
|
||||
defaults.MustSet(&config.Wildcard[i])
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ type WildcardPattern struct {
|
||||
Domain []string
|
||||
CloneURL *fasttemplate.Template
|
||||
IndexRepos []*fasttemplate.Template
|
||||
IndexBranch string
|
||||
FallbackURL *url.URL
|
||||
Fallback http.Handler
|
||||
}
|
||||
@@ -71,6 +72,7 @@ func ConfigureWildcards(configs []WildcardConfig) error {
|
||||
}
|
||||
|
||||
var indexRepoTemplates []*fasttemplate.Template
|
||||
var indexRepoBranch string = config.IndexRepoBranch
|
||||
for _, indexRepo := range config.IndexRepos {
|
||||
indexRepoTemplate, err := fasttemplate.NewTemplate(indexRepo, "<", ">")
|
||||
if err != nil {
|
||||
@@ -105,6 +107,7 @@ func ConfigureWildcards(configs []WildcardConfig) error {
|
||||
Domain: strings.Split(config.Domain, "."),
|
||||
CloneURL: cloneURLTemplate,
|
||||
IndexRepos: indexRepoTemplates,
|
||||
IndexBranch: indexRepoBranch,
|
||||
FallbackURL: fallbackURL,
|
||||
Fallback: fallback,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user