Browse Source

Sync fixes with categories page

pull/4/head
jrtechs 6 years ago
parent
commit
2c2670c031
3 changed files with 24 additions and 4 deletions
  1. +18
    -2
      posts/category.js
  2. +3
    -0
      server.js
  3. +3
    -2
      utils/sql.js

+ 18
- 2
posts/category.js View File

@ -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("</div>");
resolve();
}).catch(function(err)
{
console.log(err);
})
});
}

+ 3
- 0
server.js View File

@ -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

+ 3
- 2
utils/sql.js View File

@ -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);
});
},

Loading…
Cancel
Save