Skip to content

Commit

Permalink
Looking for Post by Slug is now case insensitive. If case does not ma…
Browse files Browse the repository at this point in the history
…tch, will do 301 redirect to the correct canonical url.

# Conflicts:
#	database/retrieval.go
  • Loading branch information
Ricardo Drizin committed Mar 10, 2016
1 parent 4ea1480 commit 17a05e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion database/retrieval.go
Expand Up @@ -15,7 +15,7 @@ const stmtRetrievePostsForApi = "SELECT id, uuid, title, slug, markdown, html, f
const stmtRetrievePostsByUser = "SELECT id, uuid, title, slug, markdown, html, featured, page, status, meta_description, image, author_id, published_at FROM posts WHERE page = 0 AND status = 'published' AND author_id = ? ORDER BY published_at DESC LIMIT ? OFFSET ?"
const stmtRetrievePostsByTag = "SELECT posts.id, posts.uuid, posts.title, posts.slug, posts.markdown, posts.html, posts.featured, posts.page, posts.status, posts.meta_description, posts.image, posts.author_id, posts.published_at FROM posts, posts_tags WHERE posts_tags.post_id = posts.id AND posts_tags.tag_id = ? AND page = 0 AND status = 'published' ORDER BY posts.published_at DESC LIMIT ? OFFSET ?"
const stmtRetrievePostById = "SELECT id, uuid, title, slug, markdown, html, featured, page, status, meta_description, image, author_id, published_at FROM posts WHERE id = ?"
const stmtRetrievePostBySlug = "SELECT id, uuid, title, slug, markdown, html, featured, page, status, meta_description, image, author_id, published_at FROM posts WHERE slug = ?"
const stmtRetrievePostBySlug = "SELECT id, uuid, title, slug, markdown, html, featured, page, status, meta_description, image, author_id, published_at FROM posts WHERE slug = ? COLLATE NOCASE"
const stmtRetrieveUserById = "SELECT id, name, slug, email, image, cover, bio, website, location FROM users WHERE id = ?"
const stmtRetrieveUserBySlug = "SELECT id, name, slug, email, image, cover, bio, website, location FROM users WHERE slug = ?"
const stmtRetrieveUserByName = "SELECT id, name, slug, email, image, cover, bio, website, location FROM users WHERE name = ?"
Expand Down
3 changes: 3 additions & 0 deletions templates/execution.go
Expand Up @@ -35,6 +35,9 @@ func ShowPostTemplate(writer http.ResponseWriter, r *http.Request, slug string)
return err
} else if !post.IsPublished { // Make sure the post is published before rendering it
return errors.New("Post not published.")
} else if post.Slug != slug {
http.Redirect(writer, r, "/"+post.Slug+"/", 301)
return nil
}
requestData := structure.RequestData{Posts: make([]structure.Post, 1), Blog: methods.Blog, CurrentTemplate: 1, CurrentPath: r.URL.Path} // CurrentTemplate = post
requestData.Posts[0] = *post
Expand Down

0 comments on commit 17a05e9

Please sign in to comment.