var Promise = require('promise');
const sql = require('../utils/sql');
const utils = require('../utils/utils.js');
var renderPosts = function(result, resultURL)
{
var splitURL = resultURL.split("/");
if(splitURL.length >= 3)
{
result.write("
\n");
return new Promise(function(resolve, reject)
{
sql.getPostsFromCategory(splitURL[2]).then(function(posts)
{
posts.forEach(function(p)
{
require("../posts/singlePost.js").renderPost(result, p);
});
}).then(function()
{
result.write("
");
resolve();
})
});
}
else
{
return utils.print404(result);
}
};
module.exports=
{
renderPostPreview: function(result, postSQLData)
{
},
/**
* Calls posts and sidebar modules to render blog contents in order
*
* @param res
* @param fileName request url
*/
main: function(res, requestURL, request)
{
console.log("category page");
return new Promise(function(resolve, reject)
{
renderPosts(res, requestURL).then(function()
{
return require("../sidebar/sidebar.js").main(res)
}).then(function ()
{
resolve();
})
});
}
}