|
@ -4,6 +4,8 @@ const sql = require('../utils/sql'); |
|
|
//file IO
|
|
|
//file IO
|
|
|
const utils = require('../utils/utils.js'); |
|
|
const utils = require('../utils/utils.js'); |
|
|
|
|
|
|
|
|
|
|
|
const batchPreview = require('../posts/renderBatchOfPreviewes'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Renders all posts in a single category |
|
|
* Renders all posts in a single category |
|
@ -11,7 +13,7 @@ const utils = require('../utils/utils.js'); |
|
|
* @param resultURL |
|
|
* @param resultURL |
|
|
* @returns {*} |
|
|
* @returns {*} |
|
|
*/ |
|
|
*/ |
|
|
const renderPosts = function(resultURL) |
|
|
|
|
|
|
|
|
const renderPosts = function(resultURL, page) |
|
|
{ |
|
|
{ |
|
|
const splitURL = resultURL.split("/"); |
|
|
const splitURL = resultURL.split("/"); |
|
|
if(splitURL.length >= 3) |
|
|
if(splitURL.length >= 3) |
|
@ -20,32 +22,10 @@ const renderPosts = function(resultURL) |
|
|
{ |
|
|
{ |
|
|
sql.getPostsFromCategory(splitURL[2]).then(function(posts) |
|
|
sql.getPostsFromCategory(splitURL[2]).then(function(posts) |
|
|
{ |
|
|
{ |
|
|
var promises = []; |
|
|
|
|
|
posts.forEach(function(p) |
|
|
|
|
|
{ |
|
|
|
|
|
promises.push(new Promise(function(res, rej) |
|
|
|
|
|
{ |
|
|
|
|
|
require("../posts/singlePost.js") |
|
|
|
|
|
.renderPreview(p).then(function(html) |
|
|
|
|
|
{ |
|
|
|
|
|
res(html); |
|
|
|
|
|
}).catch(function(error) |
|
|
|
|
|
{ |
|
|
|
|
|
rej(error); |
|
|
|
|
|
}) |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Promise.all(promises).then(function(content) |
|
|
|
|
|
{ |
|
|
|
|
|
resolve("<div class='col-md-8'>" + content.join('') + "</div>"); |
|
|
|
|
|
}).catch(function(error) |
|
|
|
|
|
{ |
|
|
|
|
|
reject(error); |
|
|
|
|
|
}); |
|
|
|
|
|
}).catch(function(err) |
|
|
|
|
|
|
|
|
resolve(batchPreview.main(resultURL, posts, page, 5)); |
|
|
|
|
|
}).catch(function(error) |
|
|
{ |
|
|
{ |
|
|
reject(err); |
|
|
|
|
|
|
|
|
reject(error); |
|
|
}) |
|
|
}) |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -67,7 +47,8 @@ module.exports= |
|
|
{ |
|
|
{ |
|
|
return new Promise(function(resolve, reject) |
|
|
return new Promise(function(resolve, reject) |
|
|
{ |
|
|
{ |
|
|
Promise.all([renderPosts(requestURL), |
|
|
|
|
|
|
|
|
var page = request.query.page; |
|
|
|
|
|
Promise.all([renderPosts(requestURL, page), |
|
|
require("../sidebar/sidebar.js").main()]).then(function(content) |
|
|
require("../sidebar/sidebar.js").main()]).then(function(content) |
|
|
{ |
|
|
{ |
|
|
resolve(content.join('')); |
|
|
resolve(content.join('')); |
|
|