|
|
@ -1,8 +1,8 @@ |
|
|
|
package caddyhugo |
|
|
|
package caddyhugo |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"html/template" |
|
|
|
"html/template" |
|
|
|
"log" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
"git.stephensearles.com/stephen/acedoc" |
|
|
|
"git.stephensearles.com/stephen/acedoc" |
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/comments" |
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/comments" |
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/media" |
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/media" |
|
|
|
|
|
|
|
"go.uber.org/zap" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2" |
|
|
|
"github.com/caddyserver/caddy/v2" |
|
|
|
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" |
|
|
|
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" |
|
|
@ -42,17 +43,20 @@ func (m *CaddyHugo) CaddyModule() caddy.ModuleInfo { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (m *CaddyHugo) Provision(ctx caddy.Context) error { |
|
|
|
func (m *CaddyHugo) Provision(ctx caddy.Context) error { |
|
|
|
|
|
|
|
m.logger = ctx.Logger(m) |
|
|
|
|
|
|
|
|
|
|
|
if m.Site.CommentsEnabled { |
|
|
|
if m.Site.CommentsEnabled { |
|
|
|
m.Comments = comments.WithStorage(comments.NewDiskv(path.Join(m.Site.Root, "comments"))) |
|
|
|
m.Comments = comments.WithStorage(comments.NewDiskv(path.Join(m.Site.Root, "comments"))) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: not sure where m.Site is getting populated.
|
|
|
|
|
|
|
|
// m.Site.Root looks to be the working directory of caddy but it needs to be the directory of the site
|
|
|
|
root, err := filepath.Abs(m.Site.Root) |
|
|
|
root, err := filepath.Abs(m.Site.Root) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
log.Println("SETTING UP") |
|
|
|
|
|
|
|
err = m.Setup(root) |
|
|
|
err = m.Setup(root) |
|
|
|
log.Println("SET UP; err:", err) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
@ -79,6 +83,8 @@ func (s *SiteConfig) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |
|
|
|
|
|
|
|
|
|
|
|
// CaddyHugo implements the plugin for a single site
|
|
|
|
// CaddyHugo implements the plugin for a single site
|
|
|
|
type CaddyHugo struct { |
|
|
|
type CaddyHugo struct { |
|
|
|
|
|
|
|
logger *zap.Logger |
|
|
|
|
|
|
|
|
|
|
|
ServerType string |
|
|
|
ServerType string |
|
|
|
Site SiteConfig |
|
|
|
Site SiteConfig |
|
|
|
HugoSites *hugolib.HugoSites |
|
|
|
HugoSites *hugolib.HugoSites |
|
|
@ -98,6 +104,17 @@ type CaddyHugo struct { |
|
|
|
confirmingToClient map[uint64]struct{} |
|
|
|
confirmingToClient map[uint64]struct{} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (ch *CaddyHugo) log(msg string, args ...interface{}) { |
|
|
|
|
|
|
|
all := make([]any, len(args)+1) |
|
|
|
|
|
|
|
all[0] = msg |
|
|
|
|
|
|
|
copy(all[1:], args) |
|
|
|
|
|
|
|
ch.logger.Info(fmt.Sprint(all...)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (ch *CaddyHugo) logf(msg string, args ...interface{}) { |
|
|
|
|
|
|
|
ch.logger.Info(fmt.Sprintf(msg, args...)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Build rebuilds the cached state of the site. TODO: determine if this republishes
|
|
|
|
// Build rebuilds the cached state of the site. TODO: determine if this republishes
|
|
|
|
func (ch *CaddyHugo) Build() error { |
|
|
|
func (ch *CaddyHugo) Build() error { |
|
|
|
return buildSite(ch.HugoSites) |
|
|
|
return buildSite(ch.HugoSites) |
|
|
|