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 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 FROM alpine

View File

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