diff --git a/blog/category.js b/blog/category.js index 8a2e5ab..67c4b2d 100644 --- a/blog/category.js +++ b/blog/category.js @@ -25,6 +25,7 @@ module.exports= templateContext["title"] = category; sql.getPostsFromCategory(category).then(function(posts) { + templateContext["categoryID"] = posts[0].category_id; Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext), require('./renderNextBar').main("/category" + request.url, page, 5, posts.length, templateContext)]).then(function() { diff --git a/blog/homePage.js b/blog/homePage.js index 912b794..2736181 100644 --- a/blog/homePage.js +++ b/blog/homePage.js @@ -13,7 +13,7 @@ module.exports= main: function(requestURL, request, templateContext) { var page = request.query.page; - + templateContext["categoryID"] = 0; return new Promise(function(resolve, reject) { sql.getAllPosts().then(function(posts) diff --git a/routes/api/index.js b/routes/api/index.js index 559368b..852ae85 100644 --- a/routes/api/index.js +++ b/routes/api/index.js @@ -15,6 +15,21 @@ routes.get('/posts', (request, result) => }); +routes.get('/preview/:postID', (request, result) => +{ + sql.getPostById(request.params.postID).then((sqlData)=> + { + renderPost.generateBlogPost(sqlData, 3).then((rendered)=> + { + result.json(rendered).end(); + }); + }).catch((err)=> + { + result.status(404).json({error: 404}).end(); + }) +}); + + routes.get('/render/:postID', (request, result) => { sql.getPostById(request.params.postID).then((sqlData)=> @@ -27,7 +42,6 @@ routes.get('/render/:postID', (request, result) => { result.status(404).json({error: 404}).end(); }) - }); routes.get('*', (request, result) => diff --git a/templates/blog/blogMain.html b/templates/blog/blogMain.html index 8657082..3367e4f 100644 --- a/templates/blog/blogMain.html +++ b/templates/blog/blogMain.html @@ -1,4 +1,132 @@ {>header} + + + + +




@@ -40,7 +168,16 @@

{/for} - {>paginationTemplate} +
+ + {if preview} +
+ More Posts » + + +
+ {/if}
diff --git a/templates/blog/header.html b/templates/blog/header.html index 04caf1e..4cc77e6 100644 --- a/templates/blog/header.html +++ b/templates/blog/header.html @@ -2,7 +2,6 @@ - {if title} Jrtechs: {title} {else} diff --git a/utils/sql.js b/utils/sql.js index 05d17be..e4f80cf 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -178,6 +178,35 @@ module.exports= }); }, + getPostIds: function(categoryID) + { + return new Promise((resolve, reject)=> + { + if(categoryID == 0) + { + fetch("select post_id from posts order by published desc") + .then(function(ids) + { + resolve(ids); + }).catch((error)=> + { + reject(error); + }); + } + else + { + fetch("select post_id from posts where category_id='" + categoryID + "' order by published desc") + .then(function(ids) + { + resolve(ids); + }).catch((error)=> + { + reject(error); + }); + } + }); + }, + insert: function(sqlStatement) { return insert(sqlStatement);