From 2595c37b72f885469a7089ad3e88d93bc0221a92 Mon Sep 17 00:00:00 2001 From: Stephen Searles Date: Tue, 1 Aug 2017 13:24:55 -0700 Subject: [PATCH] fixing filename weirdness in drafts after adjustments from testing --- caddyhugo.go | 2 +- doc_test.go | 6 ++++-- http.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/caddyhugo.go b/caddyhugo.go index 8d35bfe..bcb06cb 100644 --- a/caddyhugo.go +++ b/caddyhugo.go @@ -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 { diff --git a/doc_test.go b/doc_test.go index 0e762eb..0cba16f 100644 --- a/doc_test.go +++ b/doc_test.go @@ -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") } diff --git a/http.go b/http.go index 5865f3d..1746f9e 100644 --- a/http.go +++ b/http.go @@ -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