From 2c2670c031ecf62ccb7177320b0971179b06028b Mon Sep 17 00:00:00 2001 From: jrtechs Date: Wed, 31 Jan 2018 18:34:48 -0500 Subject: [PATCH] Sync fixes with categories page --- posts/category.js | 20 ++++++++++++++++++-- server.js | 3 +++ utils/sql.js | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/posts/category.js b/posts/category.js index 10ce9c1..269e7d3 100644 --- a/posts/category.js +++ b/posts/category.js @@ -2,6 +2,8 @@ var Promise = require('promise'); const sql = require('../utils/sql'); const utils = require('../utils/utils.js'); + + var renderPosts = function(result, resultURL) { var splitURL = resultURL.split("/"); @@ -13,15 +15,29 @@ var renderPosts = function(result, resultURL) { sql.getPostsFromCategory(splitURL[2]).then(function(posts) { + var promises = []; + console.log(posts); + console.log("^^^^"); posts.forEach(function(p) { - - require("../posts/singlePost.js").renderPost(result, p); + promises.push(new Promise(function(res, rej) + { + require("../posts/singlePost.js") + .renderPost(result, p) + .then(function() + { + res(); + }); + })); }); + return Promise.all(promises); }).then(function() { result.write(""); resolve(); + }).catch(function(err) + { + console.log(err); }) }); } diff --git a/server.js b/server.js index 816ef37..2a4a5b5 100644 --- a/server.js +++ b/server.js @@ -37,6 +37,9 @@ app.use(function(request, res) { var file = ""; + if(filename === '' || filename === '/') + filename = '/category/Java'; + var urlSplit = filename.split("/"); if(urlSplit.length >= 2 && urlSplit[1] === 'category') //single category page diff --git a/utils/sql.js b/utils/sql.js index 722c7c5..cd8befe 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -130,19 +130,20 @@ module.exports= return new Promise(function(resolve, reject) { var q = "select * from categories where name ='" + requestURL + "' limit 1"; + console.log(q); fetch(q).then(function(categories) { if(categories.length != 0) { var qPosts = "select * from posts where category_id='" + categories[0].category_id + "'"; + console.log(qPosts); resolve(fetch(qPosts)); } else { - resolve(0); + resolve([]); } }); - resolve(0); }); },