Browse Source

fixing filename weirdness in drafts after adjustments from testing

pull/8/head
Stephen Searles 2 years ago
parent
commit
2595c37b72
3 changed files with 7 additions and 5 deletions
  1. 1
    1
      caddyhugo.go
  2. 4
    2
      doc_test.go
  3. 2
    2
      http.go

+ 1
- 1
caddyhugo.go View File

@@ -68,7 +68,7 @@ func docname(orig string) string {
}

func (ch *CaddyHugo) docFilename(orig string) string {
return filepath.Join(ch.Dir, "content", docname(orig))
return filepath.Join(ch.Dir, docname(orig))
}

func (ch *CaddyHugo) Publish() error {

+ 4
- 2
doc_test.go View File

@@ -48,6 +48,8 @@ func TestEdits(t *testing.T) {
defer w.Clean()

const title = "sometitle"
var contentPath = path.Join("content", title+".md")

w.CH.NewContent(title, "")

send := []acedoc.Delta{
@@ -58,7 +60,7 @@ func TestEdits(t *testing.T) {
var mtx sync.Mutex
received := []acedoc.Delta{}

doc, err := w.CH.client(title + ".md")
doc, err := w.CH.client(contentPath)
if err != nil {
t.Fatal("error creating document client:", err)
}
@@ -71,7 +73,7 @@ func TestEdits(t *testing.T) {
return nil
}))

_, ok := w.CH.hasdocref(title + ".md")
_, ok := w.CH.hasdocref(contentPath)
if !ok {
t.Fatal("expected there to be an established client")
}

+ 2
- 2
http.go View File

@@ -179,7 +179,7 @@ func (ch *CaddyHugo) serveDraft(w http.ResponseWriter, r *http.Request) (int, er
ch.mtx.Lock()
defer ch.mtx.Unlock()

docref, ok := ch.docs[docname(name)]
docref, ok := ch.docs[ch.docFilename(name)]
if !ok {
return http.StatusNotFound, fmt.Errorf("draft not found")
}
@@ -189,7 +189,7 @@ func (ch *CaddyHugo) serveDraft(w http.ResponseWriter, r *http.Request) (int, er
prefix := "/hugo/draft/" + encoded
r.URL.Path = r.URL.Path[len(prefix):]

page := ch.HugoSites.GetContentPage(name)
page := ch.HugoSites.GetContentPage(ch.docFilename(name))
if page == nil {
fmt.Fprintf(w, "can't find %q to display a draft", name)
return 404, nil

Loading…
Cancel
Save