diff --git a/blog/sidebar.js b/blog/sidebar.js index ac82c1a..55950fc 100644 --- a/blog/sidebar.js +++ b/blog/sidebar.js @@ -45,6 +45,26 @@ const getInformationForCategories = function(templateContext) }; +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) @@ -53,6 +73,7 @@ module.exports= { Promise.all([includes.fetchTemplate(TEMPLATE_FILE), getInformationForRecentPosts(templateContext), + getInformationForPinnedPosts(templateContext), getInformationForCategories(templateContext)]) .then(function(content) { diff --git a/docs/sqlConfig.md b/docs/sqlConfig.md index cc438d6..867fdb2 100644 --- a/docs/sqlConfig.md +++ b/docs/sqlConfig.md @@ -29,9 +29,11 @@ picture_url varchar(100) not null, published datetime not null, name varchar(100) not null, url varchar(100) not null, +pinned BIT, primary key(post_id) ); +ALTER TABLE posts ADD pinned BIT; create table downloads( download_id mediumint unsigned not null AUTO_INCREMENT, diff --git a/templates/blog/sideBar.html b/templates/blog/sideBar.html index e79eb2f..7565656 100644 --- a/templates/blog/sideBar.html +++ b/templates/blog/sideBar.html @@ -34,3 +34,15 @@
+
+
+ +
Pinned Posts
+
+ {for pinnedPost in pinnedPosts} + {pinnedPost.name}
+ {/for} +
+
+
+ diff --git a/utils/sql.js b/utils/sql.js index 183eaeb..4194ef4 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -235,6 +235,36 @@ module.exports= }, + getPinnedPosts: function() + { + return new Promise(function(resolve, reject) + { + var q = "select name,url, category_id from posts where pinned=1 order " + + "by post_id desc limit 10"; + console.log(q); + fetch(q).then(function (sqlPosts) { + var promises = []; + sqlPosts.forEach(function (post) { + promises.push(new Promise(function (res, rej) { + var getCategory = "select url from categories where " + + "category_id='" + post.category_id + "'"; + fetch(getCategory).then(function (urls) { + var obj = new Object(); + obj.name = post.name; + obj.url = post.url; + obj.category = urls[0].url; + res(obj); + }); + })); + }); + Promise.all(promises).then(function (goodies) { + resolve(goodies); + }); + }); + }); + }, + + /** * TODO * @returns {*|Promise}