add option to either use fixed org repo or use github style nameing

This commit is contained in:
ebner 2025-03-03 14:37:28 +01:00
parent 28b9ac94f5
commit 0842be001b
3 changed files with 24 additions and 10 deletions

View File

@ -1,6 +1,6 @@
FROM caddy:builder-alpine AS builder
RUN xcaddy build --with github.com/simongregorebner/gitea-pages@v0.0.5
RUN xcaddy build --with github.com/simongregorebner/gitea-pages@v0.0.6
FROM alpine

View File

@ -89,7 +89,8 @@ log {
| server | The URL of your Gitea server. |
| token | Your access token for the Gitea API. This token is used to authenticate requests made to the Gitea server.|
| pages_branch | The branch in your repository that contains the static files for your website or documentation. By default, this would be the branch "gitea-pages" |
| postfix_pages_repository | The (domain) postfix used for the pages repository. (This could be the domain where your site will be accessible, such as "gitea.io".) |
| pages_repository | The default repository of an organization |
| postfix_pages_repository | The (domain) postfix used for the pages repository. __This setting is only used if pages_repository is not set!__ (This could be the domain where your site will be accessible, such as "gitea.io".) |
| url_scheme | The URL scheme to use for the pages. "simple" or "classic |

View File

@ -34,6 +34,7 @@ type GiteaPagesModule struct {
Server string `json:"server,omitempty"`
Token string `json:"token,omitempty"`
PagesBranch string `json:"pages_branch,omitempty"`
PagesRepository string `json:"pages_repository,omitempty"`
PostfixPagesRepository string `json:"postfix_pages_repository,omitempty"`
URLScheme string `json:"url_scheme,omitempty"`
}
@ -65,6 +66,8 @@ func (module *GiteaPagesModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
d.Args(&module.Token)
case "pages_branch":
d.Args(&module.PagesBranch)
case "pages_repository":
d.Args(&module.PagesBranch)
case "postfix_pages_repository":
d.Args(&module.PostfixPagesRepository)
case "url_scheme":
@ -76,9 +79,11 @@ func (module *GiteaPagesModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
if module.PagesBranch == "" {
module.PagesBranch = "gitea-pages"
}
if module.PagesRepository == "" {
if module.PostfixPagesRepository == "" {
module.PostfixPagesRepository = "gitea-pages"
}
}
if module.URLScheme == "" {
module.URLScheme = "simple"
@ -131,9 +136,13 @@ func (module GiteaPagesModule) ServeHTTP(writer http.ResponseWriter, request *ht
// Case http(s)://<organization>.<giteaserver>[:<port>]
// (Try to) Use of the pages repository in the specified organization
// Determine name of the default repository for organization based on settings
if module.PagesRepository != "" {
repository = module.PagesRepository
} else {
// We use github.com conventions: <organization>.github.io
// repository = organization + "." + module.PostfixPagesRepository
repository = module.PostfixPagesRepository
repository = organization + "." + module.PostfixPagesRepository
}
path = "index.html"
} else {
@ -153,9 +162,13 @@ func (module GiteaPagesModule) ServeHTTP(writer http.ResponseWriter, request *ht
}
} else {
// (Try to) Use of the pages repository in the specified organization
// Determine name of the default repository for organization based on settings
if module.PagesRepository != "" {
repository = module.PagesRepository
} else {
// We use github.com conventions: <organization>.github.io
// repository = organization + "." + module.PostfixPagesRepository
repository = module.PostfixPagesRepository
repository = organization + "." + module.PostfixPagesRepository
}
path = strings.Join(parts[0:], "/")
}
}