wip: drafts done with hugolib
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
package caddyhugo
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"git.stephensearles.com/stephen/acedoc"
|
||||
"git.stephensearles.com/stephen/idleshut"
|
||||
)
|
||||
@@ -18,7 +18,7 @@ type editSession struct {
|
||||
docname string
|
||||
filename string
|
||||
doc *acedoc.Document
|
||||
tmpdir string
|
||||
tmpfs afero.Fs
|
||||
mtx sync.Mutex
|
||||
}
|
||||
|
||||
@@ -38,16 +38,16 @@ func (ch *CaddyHugo) newEditSession(docName string) (*editSession, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
draftPrefix := fmt.Sprintf("draft-%s", base64.RawURLEncoding.EncodeToString([]byte(docName)))
|
||||
tmpdir := path.Join(os.TempDir(), draftPrefix)
|
||||
|
||||
es := &editSession{
|
||||
docname: docName,
|
||||
filename: filename,
|
||||
doc: acedoc.NewString(string(contents)),
|
||||
tmpdir: tmpdir,
|
||||
// tmpfs: afero.NewCopyOnWriteFs(afero.NewBasePathFs(afero.NewOsFs(), ch.Dir+"/"), afero.NewMemMapFs()),
|
||||
tmpfs: afero.NewCopyOnWriteFs(afero.NewReadOnlyFs(afero.NewBasePathFs(afero.NewOsFs(), ch.Dir)), afero.NewMemMapFs()),
|
||||
}
|
||||
|
||||
printTree(es.tmpfs)
|
||||
|
||||
err = es.doc.LogToFile(path.Join(ch.Dir, "logs", docName))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -56,7 +56,10 @@ func (ch *CaddyHugo) newEditSession(docName string) (*editSession, error) {
|
||||
|
||||
ch.docs[filename] = es
|
||||
|
||||
ch.renderDraft(es)
|
||||
err = ch.renderDraft(es)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return es, nil
|
||||
}
|
||||
@@ -70,9 +73,13 @@ func (ch *CaddyHugo) renderDraft(es *editSession) error {
|
||||
}
|
||||
}
|
||||
|
||||
proc = idleshut.New(HugoCmdProcessConfig(ch, es, f))
|
||||
cfg, err := HugoCmdProcessConfig(ch, es, f)
|
||||
if err != nil {
|
||||
return fmt.Errorf("rendering draft: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
proc = idleshut.New(cfg)
|
||||
return proc.Start()
|
||||
}
|
||||
|
||||
func (ch *CaddyHugo) hasEditSession(docName string) (*editSession, bool) {
|
||||
|
||||
Reference in New Issue
Block a user