pages-server/pagerouter/utils.go
hazycora 1f5472a177
All checks were successful
Deploy to VPS / build_site (push) Successful in 3s
fix basePath
2024-04-07 20:07:16 -05:00

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
}
}