log improvements; todo with question
This commit is contained in:
+20
-3
@@ -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)
|
||||
|
||||
@@ -98,6 +98,7 @@ func (ch *CaddyHugo) NewContent(name, ctype string) (string, error) {
|
||||
if os.IsNotExist(err) {
|
||||
cmd := exec.Command("hugo", "new", filename)
|
||||
cmd.Dir = ch.Dir
|
||||
ch.logf(ch.Dir)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return filename, fmt.Errorf("error running 'hugo new': %v; %v", err, string(out))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module git.stephensearles.com/stephen/caddy-hugo2
|
||||
|
||||
go 1.16
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
git.stephensearles.com/stephen/acedoc v0.0.0-20170928122432-96da2793a59d
|
||||
|
||||
@@ -3,7 +3,6 @@ package caddyhugo
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
@@ -49,7 +48,7 @@ func (ch *CaddyHugo) commentsSetting() {
|
||||
func (ch *CaddyHugo) Setup(dir string) error {
|
||||
var err error
|
||||
|
||||
log.Println("setting up caddy-hugo in", dir)
|
||||
ch.log("setting up caddy-hugo in", dir)
|
||||
ch.Dir = dir
|
||||
ch.docs = make(map[string]*editSession)
|
||||
ch.confirmingToClient = make(map[uint64]struct{})
|
||||
|
||||
Reference in New Issue
Block a user