diff --git a/caddyhugo.go b/caddyhugo.go index 447fd0a..33cd523 100644 --- a/caddyhugo.go +++ b/caddyhugo.go @@ -19,13 +19,13 @@ import ( "git.stephensearles.com/stephen/acedoc" "git.stephensearles.com/stephen/caddy-hugo2/assets" + "github.com/gohugoio/hugo/deps" + "github.com/gohugoio/hugo/hugofs" + "github.com/gohugoio/hugo/hugolib" "github.com/gorilla/websocket" "github.com/mholt/caddy" "github.com/mholt/caddy/caddyhttp/httpserver" "github.com/spf13/afero" - "github.com/spf13/hugo/deps" - "github.com/spf13/hugo/hugofs" - "github.com/spf13/hugo/hugolib" ) const ( @@ -321,7 +321,15 @@ 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) + if page == nil { + fmt.Fprintf(w, "can't find %q to display a draft", name) + return 404, nil + } + + r.URL.Path = page.RelPermalink() http.FileServer(http.Dir(docref.tmpdir)).ServeHTTP(w, r) + return 200, nil } @@ -512,11 +520,9 @@ func (ch CaddyHugo) NewContent(w http.ResponseWriter, r *http.Request) (int, err name += ".md" } - name = strings.ToLower(name) - - filename := path.Join(ctype, name) + filename := path.Join(ctype, strings.ToLower(name)) if ctype == "default" { - filename = name + filename = strings.ToLower(name) } _, err := os.Stat(path.Join(ch.Site.Root, "content", filename)) diff --git a/templates.go b/templates.go index 789fadb..a8a2196 100644 --- a/templates.go +++ b/templates.go @@ -12,8 +12,8 @@ import ( "git.stephensearles.com/stephen/acedoc" + "github.com/gohugoio/hugo/hugolib" "github.com/mholt/caddy/caddyhttp/httpserver" - "github.com/spf13/hugo/hugolib" ) type Content struct {