From 87ab783dc3af612263939d53b3f3ae3706fae401 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Wed, 17 Jun 2020 20:24:44 -0400 Subject: [PATCH 1/2] added more posts and functionality to load previews --- routes/api/index.js | 16 ++++- templates/blog/blogMain.html | 125 ++++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 2 deletions(-) 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..de4c18c 100644 --- a/templates/blog/blogMain.html +++ b/templates/blog/blogMain.html @@ -1,4 +1,116 @@ {>header} + + + + +




@@ -40,7 +152,18 @@

{/for} - {>paginationTemplate} +
+ + {if preview} +
+
+

+ More Posts » +

+
+
+ {/if}
From 30236674def1ce21a055836dfca27b96520ad428 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Thu, 18 Jun 2020 19:56:31 -0400 Subject: [PATCH 2/2] Finished more posts load system --- blog/category.js | 1 + blog/homePage.js | 2 +- templates/blog/blogMain.html | 36 +++++++++++++++++++++++++----------- templates/blog/header.html | 1 - utils/sql.js | 29 +++++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 13 deletions(-) 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/templates/blog/blogMain.html b/templates/blog/blogMain.html index de4c18c..3367e4f 100644 --- a/templates/blog/blogMain.html +++ b/templates/blog/blogMain.html @@ -7,7 +7,7 @@




@@ -155,13 +171,11 @@
{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);