|
|
|
@ -1,8 +1,8 @@ |
|
|
|
|
package caddyhugo |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"html/template" |
|
|
|
|
"log" |
|
|
|
|
"net/http" |
|
|
|
|
"path" |
|
|
|
|
"path/filepath" |
|
|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
|
"git.stephensearles.com/stephen/acedoc" |
|
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/comments" |
|
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/media" |
|
|
|
|
"go.uber.org/zap" |
|
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2" |
|
|
|
|
"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 { |
|
|
|
|
m.logger = ctx.Logger(m) |
|
|
|
|
|
|
|
|
|
if m.Site.CommentsEnabled { |
|
|
|
|
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) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
log.Println("SETTING UP") |
|
|
|
|
|
|
|
|
|
err = m.Setup(root) |
|
|
|
|
log.Println("SET UP; err:", err) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
@ -79,6 +83,8 @@ func (s *SiteConfig) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |
|
|
|
|
|
|
|
|
|
// CaddyHugo implements the plugin for a single site
|
|
|
|
|
type CaddyHugo struct { |
|
|
|
|
logger *zap.Logger |
|
|
|
|
|
|
|
|
|
ServerType string |
|
|
|
|
Site SiteConfig |
|
|
|
|
HugoSites *hugolib.HugoSites |
|
|
|
@ -98,6 +104,17 @@ type CaddyHugo 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
|
|
|
|
|
func (ch *CaddyHugo) Build() error { |
|
|
|
|
return buildSite(ch.HugoSites) |
|
|
|
|