Make gitea-pages variable
This commit is contained in:
parent
9ed3fcd793
commit
9120ac1d28
11
gitea.go
11
gitea.go
@ -25,9 +25,10 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
|
|||||||
|
|
||||||
// Middleware implements gitea plugin.
|
// Middleware implements gitea plugin.
|
||||||
type Middleware struct {
|
type Middleware struct {
|
||||||
Client *gitea.Client `json:"-"`
|
Client *gitea.Client `json:"-"`
|
||||||
Server string `json:"server,omitempty"`
|
Server string `json:"server,omitempty"`
|
||||||
Token string `json:"token,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
|
GiteaPages string `json:"gitea_pages,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CaddyModule returns the Caddy module information.
|
// CaddyModule returns the Caddy module information.
|
||||||
@ -40,7 +41,7 @@ func (Middleware) CaddyModule() caddy.ModuleInfo {
|
|||||||
|
|
||||||
// Provision provisions gitea client.
|
// Provision provisions gitea client.
|
||||||
func (m *Middleware) Provision(ctx caddy.Context) error {
|
func (m *Middleware) Provision(ctx caddy.Context) error {
|
||||||
m.Client = gitea.NewClient(m.Server, m.Token)
|
m.Client = gitea.NewClient(m.Server, m.Token, m.GiteaPages)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -59,6 +60,8 @@ func (m *Middleware) UnmarshalCaddyfile(d *caddyfile.Dispenser) (err error) {
|
|||||||
d.Args(&m.Server)
|
d.Args(&m.Server)
|
||||||
case "token":
|
case "token":
|
||||||
d.Args(&m.Token)
|
d.Args(&m.Token)
|
||||||
|
case "gitea_pages":
|
||||||
|
d.Args(&m.GiteaPages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
serverURL string
|
serverURL string
|
||||||
token string
|
token string
|
||||||
|
giteapages string
|
||||||
}
|
}
|
||||||
|
|
||||||
type pagesConfig struct {
|
type pagesConfig struct {
|
||||||
@ -27,16 +28,21 @@ type topicsResponse struct {
|
|||||||
Topics []string `json:"topics"`
|
Topics []string `json:"topics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(serverURL, token string) *Client {
|
func NewClient(serverURL, token, giteapages string) *Client {
|
||||||
|
if giteapages == "" {
|
||||||
|
giteapages = "gitea-pages"
|
||||||
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
serverURL: serverURL,
|
serverURL: serverURL,
|
||||||
token: token,
|
token: token,
|
||||||
|
giteapages: giteapages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Open(name, ref string) (fs.File, error) {
|
func (c *Client) Open(name, ref string) (fs.File, error) {
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
ref = "gitea-pages"
|
ref = c.giteapages
|
||||||
}
|
}
|
||||||
|
|
||||||
owner, repo, filepath, err := splitName(name)
|
owner, repo, filepath, err := splitName(name)
|
||||||
@ -186,7 +192,7 @@ func (c *Client) allowsPages(owner, repo string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, topic := range topics {
|
for _, topic := range topics {
|
||||||
if topic == "gitea-pages" {
|
if topic == c.giteapages {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -195,7 +201,7 @@ func (c *Client) allowsPages(owner, repo string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) readConfig(owner, repo string) error {
|
func (c *Client) readConfig(owner, repo string) error {
|
||||||
cfg, err := c.getRawFileOrLFS(owner, repo, "gitea-pages.toml", "gitea-pages")
|
cfg, err := c.getRawFileOrLFS(owner, repo, c.giteapages+".toml", c.giteapages)
|
||||||
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
if err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user