forked from deadvey/blogger-nodejs
Basic search functionality on the frontpage, I want to add support for
more advanced searches like using boolean operators, but right now it's pretty basic.
This commit is contained in:
10
src/data.js
10
src/data.js
@@ -8,7 +8,7 @@ const fs = require("fs")
|
||||
export function searchdata(term, type) { // Searches users and posts for any matches
|
||||
let search_results = {"posts": [], "users": []};
|
||||
// Search users
|
||||
if (type == 'post' || type == 'any') {
|
||||
if (type.includes('post')) {
|
||||
let list = getdata('posts');
|
||||
list.forEach((element,index) => {
|
||||
if (typeof element.deleted == 'undefined' || element.deleted == false) {
|
||||
@@ -24,18 +24,18 @@ export function searchdata(term, type) { // Searches users and posts for any mat
|
||||
};
|
||||
});
|
||||
}
|
||||
if (type == 'user' || type == 'any') {
|
||||
if (type.includes('user')) {
|
||||
let list = getdata('users');
|
||||
list.forEach((element,index) => {
|
||||
if (typeof element.deleted == 'undefined' || element.deleted == false) {
|
||||
if (element.username.includes(term)) {
|
||||
search_results.posts.push(element)
|
||||
search_results.users.push(element)
|
||||
}
|
||||
else if (element.prettyname.includes(term)) {
|
||||
search_results.posts.push(element)
|
||||
search_results.users.push(element)
|
||||
}
|
||||
else if (element.description.includes(term)) {
|
||||
search_results.posts.push(element)
|
||||
search_results.users.push(element)
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user