41 lines
965 B
Go
41 lines
965 B
Go
package pagerouter
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.gay/gitgay/pages/forgejo"
|
|
)
|
|
|
|
func getPotentialRepoName(path string) string {
|
|
pathParts := strings.Split(strings.TrimPrefix(path, "/"), "/")
|
|
reponame := pathParts[0]
|
|
return reponame
|
|
}
|
|
|
|
func getPotentialRepo(owner string, repoName string) (*forgejo.Repository, error) {
|
|
repository, err := forgejo.GetRepo(owner, repoName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for _, branch := range repository.Branches {
|
|
if branch.Name == "pages" {
|
|
return repository, nil
|
|
}
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func CleanPathsOfRouter(pageRouter *PageRouter) {
|
|
newFiles := make(map[string]forgejo.TreeFile)
|
|
if pageRouter.Settings.BasePath != "" {
|
|
for path, file := range pageRouter.Files {
|
|
if !strings.HasPrefix(path, pageRouter.Settings.BasePath) {
|
|
continue
|
|
}
|
|
filePath := strings.TrimPrefix(strings.TrimPrefix(path, "/"), pageRouter.Settings.BasePath)
|
|
newFiles[filePath] = file
|
|
}
|
|
pageRouter.Files = newFiles
|
|
}
|
|
}
|