Browse Source

Controllers+JS: Search in blog contents, fix special character search

master
Riyyi 2 years ago
parent
commit
ee40846bd6
  1. 4
      app/controllers/BlogController.php
  2. 4
      public/js/site.js

4
app/controllers/BlogController.php

@ -41,7 +41,9 @@ class BlogController extends PageController {
LEFT JOIN section ON page.section_id = section.id
LEFT JOIN log ON blog_post.log_id = log.id
WHERE blog_post.archived = 0 AND
(blog_post.title LIKE :query OR blog_post.tag LIKE :query)
(blog_post.content LIKE :query OR
blog_post.title LIKE :query OR
blog_post.tag LIKE :query)
', [[':query', "%$query%", \PDO::PARAM_STR]]);
}

4
public/js/site.js

@ -19,7 +19,7 @@ $(document).ready(function() {
{
var url = input.data("url");
var search = input.val();
window.location.href = url + '?search=' + search;
window.location.href = url + '?search=' + encodeURIComponent(search);
}
$("#js-blog-search").keydown(function(e) {
@ -37,7 +37,7 @@ $(document).ready(function() {
var url = $(this).data("url");
var search = $(this).val();
if (search.length == 0 || search.length >= 3) {
fetch(url + '/search?query=' + search)
fetch(url + '/search?query=' + encodeURIComponent(search))
.then(response => response.text())
.then(data => {
$("#blog-posts").empty().append(data);

Loading…
Cancel
Save