|
|
|
@ -2,6 +2,7 @@ package caddyhugo |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"path" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/gohugoio/hugo/deps" |
|
|
|
@ -29,15 +30,15 @@ type HugoRenderer interface { |
|
|
|
|
|
|
|
|
|
func HugoCmdProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (idleshut.Config, error) { |
|
|
|
|
|
|
|
|
|
printTree(es.tmpfs) |
|
|
|
|
var err error |
|
|
|
|
hugoCfg := &deps.DepsCfg{Fs: hugofs.NewFrom(es.tmpfs, ch.HugoCfg.Cfg)} |
|
|
|
|
hugoCfg.Cfg, err = hugolib.LoadConfig(es.tmpfs, "/", "config.toml") |
|
|
|
|
fmt.Println(ch.Dir) |
|
|
|
|
hugoCfg.Cfg, err = hugolib.LoadConfig(es.tmpfs, "", path.Join(ch.Dir, "config.toml")) |
|
|
|
|
if err != nil { |
|
|
|
|
return idleshut.Config{}, fmt.Errorf("caddy-hugo: loading site configuration: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hugoCfg.Cfg.Set("workingdir", "/") |
|
|
|
|
hugoCfg.Cfg.Set("workingDir", ch.Dir) |
|
|
|
|
hugoSites, err := hugolib.NewHugoSites(*hugoCfg) |
|
|
|
|
if err != nil { |
|
|
|
|
return idleshut.Config{}, fmt.Errorf("caddy-hugo: initializing site: %v", err) |
|
|
|
@ -53,15 +54,20 @@ func HugoCmdProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (idles |
|
|
|
|
TickDuration: WebsocketFileTicker, |
|
|
|
|
MaxIdleTicks: uint(IdleWebsocketTimeout/WebsocketFileTicker) + 1, |
|
|
|
|
Stop: func() error { |
|
|
|
|
ch.persistEdits(es) |
|
|
|
|
|
|
|
|
|
es.doc.Close() |
|
|
|
|
|
|
|
|
|
ch.mtx.Lock() |
|
|
|
|
defer ch.mtx.Unlock() |
|
|
|
|
delete(ch.docs, es.filename) |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
}, |
|
|
|
|
TickError: func(err error) { |
|
|
|
|
fmt.Println("error processing draft:", err) |
|
|
|
|
}, |
|
|
|
|
Tick: func() error { |
|
|
|
|
fmt.Println("TICK") |
|
|
|
|
err := afero.WriteFile(es.tmpfs, es.filename, []byte(es.doc.Contents()), 0644) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|