Skip to content

Commit

Permalink
Fixed: Trailing slash redirection when using pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabukky committed May 6, 2015
1 parent 8544216 commit a34b6fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions server/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ package server
import (
"github.com/dimfeld/httptreemux"
"github.com/kabukky/journey/filenames"
"github.com/kabukky/journey/helpers"
"net/http"
"path/filepath"
"strings"
)

func pagesHandler(w http.ResponseWriter, r *http.Request, params map[string]string) {
http.ServeFile(w, r, filepath.Join(filenames.PagesFilepath, params["filepath"]))
path := filepath.Join(filenames.PagesFilepath, params["filepath"])
// If the path points to a directory, add a trailing slash to the path (needed if the page loads relative assets).
if helpers.IsDirectory(path) && !strings.HasSuffix(r.RequestURI, "/") {
http.Redirect(w, r, r.RequestURI+"/", 301)
return
}
http.ServeFile(w, r, path)
return
}

func InitializePages(router *httptreemux.TreeMux) {
// For serving standalone projects or pages saved in in content/pages
router.GET("/pages/*filepath/", pagesHandler)
router.GET("/pages/*filepath", pagesHandler)
}
4 changes: 2 additions & 2 deletions templates/handlebars.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ func atOddFunc(helper *structure.Helper, values *structure.RequestData) []byte {
}

func nameFunc(helper *structure.Helper, values *structure.RequestData) []byte {
// If tag (commented out the code for generating a link. Ghost doesn't seem to do that either.
// If tag (commented out the code for generating a link. Ghost doesn't seem to do that either).
if values.CurrentHelperContext == 2 { // tag
//var buffer bytes.Buffer
//buffer.WriteString("<a href=\"")
Expand All @@ -753,7 +753,7 @@ func nameFunc(helper *structure.Helper, values *structure.RequestData) []byte {
//return buffer.Bytes()
return evaluateEscape(values.Posts[values.CurrentPostIndex].Tags[values.CurrentTagIndex].Name, helper.Unescaped)
}
// If author (commented out the code for generating a link. Ghost doesn't seem to do that.
// If author (commented out the code for generating a link. Ghost doesn't seem to do that).
//var buffer bytes.Buffer
//buffer.WriteString("<a href=\"")
//buffer.WriteString("/author/")
Expand Down

0 comments on commit a34b6fd

Please sign in to comment.