Skip to content

Commit

Permalink
Looking for Post by Slug is now case insensitive. If case doesn't mat…
Browse files Browse the repository at this point in the history
…ch, 301 redirect to the correct canonical url.

kabukky#82
  • Loading branch information
Kami-no committed May 15, 2019
1 parent 889eb2c commit cf0a9e6
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 cf0a9e6

Please sign in to comment.