Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

88 lines
2.2 KiB

const sql = require('../utils/sql');
const TEMPLATE_FILE = "blog/sideBar.html";
const includes = require('../includes/includes.js');
const getInformationForRecentPosts = function(templateContext)
{
return new Promise(function(resolve, reject)
{
sql.getRecentPosts().then(function(posts)
{
posts.forEach(function(p)
{
p.url = '/' + p.category + '/' + p.url;
});
templateContext.recentPosts = posts;
resolve();
}).catch(function(error)
{
reject(error);
})
});
};
const getInformationForCategories = function(templateContext)
{
return new Promise(function(resolve, reject)
{
sql.getCategories().then(function(categories)
{
categories.forEach(function(cat)
{
cat.url = "/category/" + cat.url;
});
templateContext.categories = categories;
resolve();
}).catch(function(error)
{
reject(error);
});
});
};
const getInformationForPinnedPosts = function(templateContext)
{
return new Promise(function(resolve, reject)
{
sql.getPinnedPosts().then(function(posts)
{
posts.forEach(function(p)
{
p.url = '/' + p.category + '/' + p.url;
});
templateContext.pinnedPosts = posts;
resolve();
}).catch(function(error)
{
reject(error);
})
});
};
module.exports=
{
main: function(templateContext)
{
return new Promise(function(resolve, reject)
{
Promise.all([includes.fetchTemplate(TEMPLATE_FILE),
getInformationForRecentPosts(templateContext),
getInformationForPinnedPosts(templateContext),
getInformationForCategories(templateContext)])
.then(function(content)
{
templateContext.sideBar = content[0];
resolve();
}).catch(function(error)
{
reject(error);
});
})
}
};