fixes from looking at PR

pull/8/head
Stephen Searles 7 years ago
parent 95f3e41f1e
commit c609179dfa
  1. 10
      caddyhugo.go
  2. 19
      client.go
  3. 29
      http.go
  4. 5
      hugo.go

@ -75,15 +75,13 @@ func (ch *CaddyHugo) docFilename(orig string) string {
// Publish really renders new content into the public directory
func (ch *CaddyHugo) Publish() error {
ch.mtx.Lock()
for _, es := range ch.docs {
ch.persistEdits(es)
err := ch.persistAllEdits()
if err != nil {
return err
}
ch.mtx.Unlock()
cmd := exec.Command("hugo")
cmd.Dir = ch.Dir
_, err := cmd.CombinedOutput()
_, err = cmd.CombinedOutput()
if err != nil {
return err
}

@ -42,8 +42,7 @@ func (ch *CaddyHugo) newEditSession(docName string) (*editSession, error) {
docname: docName,
filename: filename,
doc: acedoc.NewString(string(contents)),
// tmpfs: afero.NewCopyOnWriteFs(afero.NewBasePathFs(afero.NewOsFs(), ch.Dir+"/"), afero.NewMemMapFs()),
tmpfs: afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs()),
tmpfs: afero.NewCopyOnWriteFs(afero.NewOsFs(), afero.NewMemMapFs()),
}
err = es.doc.LogToFile(path.Join(ch.Dir, "logs", docName))
@ -71,7 +70,7 @@ func (ch *CaddyHugo) renderDraft(es *editSession) error {
}
}
cfg, err := HugoCmdProcessConfig(ch, es, f)
cfg, err := HugoInternalProcessConfig(ch, es, f)
if err != nil {
return fmt.Errorf("rendering draft: %v", err)
}
@ -80,7 +79,19 @@ func (ch *CaddyHugo) renderDraft(es *editSession) error {
return proc.Start()
}
func (ch *CaddyHugo) persistEdits(es *editSession) error {
func (ch *CaddyHugo) persistAllEdits() error {
ch.mtx.Lock()
defer ch.mtx.Unlock()
for _, es := range ch.docs {
err := ch.persistEditsForSession(es)
if err != nil {
return err
}
}
return nil
}
func (ch *CaddyHugo) persistEditsForSession(es *editSession) error {
err := afero.WriteFile(afero.NewOsFs(), es.filename, []byte(es.doc.Contents()), 0644)
if err != nil {
return err

@ -215,35 +215,6 @@ func (ch *CaddyHugo) serveDraft(w http.ResponseWriter, r *http.Request) (int, er
return 200, nil
}
func printTree(fs afero.Fs) {
const tab = " "
afero.Walk(fs, "/", filepath.WalkFunc(func(path string, info os.FileInfo, err error) error {
if filepath.Base(path) == ".git" {
return filepath.SkipDir
}
if err != nil && !os.IsNotExist(err) {
fmt.Println(err)
return err
} else if err != nil {
return nil
}
nIndent := len(strings.Split(path, string(filepath.Separator))) - 1
indent := strings.Repeat(tab, nIndent)
if info.IsDir() {
fmt.Printf("%s├ %s\n", indent, info.Name())
nIndent++
} else {
fmt.Printf("%s| %s\t%d\n", indent, info.Name(), info.Size())
}
return nil
}))
}
type aferoHTTP struct {
afero.Fs
}

@ -28,7 +28,7 @@ type HugoRenderer interface {
Stop() error
}
func HugoCmdProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (idleshut.Config, error) {
func HugoInternalProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (idleshut.Config, error) {
var err error
hugoCfg := &deps.DepsCfg{Fs: hugofs.NewFrom(es.tmpfs, ch.HugoCfg.Cfg)}
@ -46,7 +46,6 @@ func HugoCmdProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (idles
err = hugoSites.Build(hugolib.BuildCfg{ResetState: true})
if err != nil {
// TODO better
return idleshut.Config{}, fmt.Errorf("caddy-hugo: building site: %v", err)
}
@ -54,7 +53,7 @@ func HugoCmdProcessConfig(ch *CaddyHugo, es *editSession, touchFn func()) (idles
TickDuration: WebsocketFileTicker,
MaxIdleTicks: uint(IdleWebsocketTimeout/WebsocketFileTicker) + 1,
Stop: func() error {
ch.persistEdits(es)
ch.persistEditsForSession(es)
es.doc.Close()

Loading…
Cancel
Save