diff --git a/posts/pages.js b/posts/pages.js
new file mode 100644
index 0000000..e69de29
diff --git a/posts/posts.js b/posts/posts.js
index ecd6f1a..cd7e03f 100644
--- a/posts/posts.js
+++ b/posts/posts.js
@@ -21,6 +21,7 @@ var renderPost = function(res, requestURL)
//user entered /category/name/ or /category/name
if(splitURL.length == 3 || splitURL.length == 4)
{
+ console.log("importante "+ requestURL)
sql.getPost(requestURL).then(function(post)
{
if(post != 0)
diff --git a/server.js b/server.js
index 9cc849a..d6a407c 100644
--- a/server.js
+++ b/server.js
@@ -29,15 +29,22 @@ http.createServer(function (request, res)
{
var file = "";
- if(filename.includes("/categories/")) //single category page
+ var urlSplit = filename.split("/");
+
+ console.log(urlSplit);
+
+ if(urlSplit.length >= 2 && urlSplit[1] === 'category') //single category page
file = "./posts/category.js";
- else if(filename.includes("/admin")) //top secret admin page
+ else if(urlSplit.length >= 2 && urlSplit[1] === 'admin') //top secret admin page
file = "./admin/admin.js";
- else //single post page
+ else if(urlSplit.length >= 3)//single post page
file = "./posts/posts.js";
+ else //single static page?
+ file = "./posts/pages.js";
+
console.log(file);
includes.printHeader(res).then(function()
diff --git a/sidebar/categoriesSideBar.js b/sidebar/categoriesSideBar.js
index 95b9c4f..c4f8d30 100644
--- a/sidebar/categoriesSideBar.js
+++ b/sidebar/categoriesSideBar.js
@@ -12,20 +12,15 @@ module.exports=
*/
main: function(res)
{
+ console.log("sidebar called");
return new Promise(function(resolve, reject)
{
- res.write("
");
+ res.write("
");
- res.write("
\n" +
- "\n" +
- "
Categories
\n" +
- "\n" +
- " ");
+ res.write("
Categories
");
+ res.write("
");
- res.write("");
-
- res.write("
");
sql.getCategories().then(function(categories)
{
console.log(categories[0].name);
@@ -33,15 +28,16 @@ module.exports=
{
//res.write(cat.name);
console.log(cat);
+ res.write("- ");
+
+ res.write("" + cat.name + "
");
+ res.write(" ");
- res.write("" + cat.name + "");
- res.write("
");
});
- res.write("
");
- res.write("
");
+ res.write("");
resolve();
})
});
}
- };
\ No newline at end of file
+ };
diff --git a/sidebar/popularPosts.js b/sidebar/popularPosts.js
index e6f5bdf..ade7d62 100644
--- a/sidebar/popularPosts.js
+++ b/sidebar/popularPosts.js
@@ -1,70 +1,43 @@
const Promise = require('promise');
+const sql = require('../utils/sql');
module.exports=
{
main: function(res)
{
+ console.log("sidebar called");
return new Promise(function(resolve, reject)
{
- res.write("Popular posts");
- resolve();
- })
- }
- };
-
-/*
-
-
-
-
-
-
-
Popular Posts
-
-
-
-
-
- -
-
-
- Lorem
-
- Sed mattis nunc
-
-
- -
+ res.write("
");
+ res.write("
\n" +
+ "\n" +
+ "
Popular Posts
\n" +
+ "\n" +
+ " ");
-
Ipsum
-
Praes tinci sed
+ res.write("
");
-
+ sql.getCategories().then(function(categories)
+ {
+ console.log(categories[0].name);
+ categories.forEach(function(cat)
+ {
+ //res.write(cat.name);
+ console.log(cat);
+ res.write("- ");
+ //res.write("" + cat.name + "");
-
-
+ res.write("" + cat.name + "
");
+ res.write(" ");
+ });
+ res.write("
");
+ resolve();
+ })
- Dorum
-
- Ultricies congue
-
-
-
- -
-
-
-
- Mingsum
-
- Lorem ipsum dipsum
-
-
-
-
-
-
-
-
- */
\ No newline at end of file
+ });
+ }
+ };
\ No newline at end of file
diff --git a/sidebar/recentPosts.js b/sidebar/recentPosts.js
new file mode 100644
index 0000000..5a194eb
--- /dev/null
+++ b/sidebar/recentPosts.js
@@ -0,0 +1,33 @@
+const Promise = require('promise');
+const sql = require('../utils/sql');
+
+module.exports=
+ {
+ main: function(res)
+ {
+ console.log("sidebar called");
+ return new Promise(function(resolve, reject)
+ {
+
+ res.write("
");
+
+ res.write("
Recent Posts
");
+
+ res.write("
");
+
+ sql.getRecentPosts().then(function(posts)
+ {
+ posts.forEach(function(p)
+ {
+ var url = '\\' + p.category + '\\' + p.name;
+ res.write("- ");
+ res.write("" + p.name + "
");
+ res.write(" ");
+ });
+ res.write("
");
+ resolve();
+ })
+
+ });
+ }
+ };
\ No newline at end of file
diff --git a/sidebar/sidebar.html b/sidebar/sidebar.html
index a4cb471..40eb8a4 100644
--- a/sidebar/sidebar.html
+++ b/sidebar/sidebar.html
@@ -2,9 +2,9 @@
-
My Name
+
Jrtechs
-
Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.
+
fda
diff --git a/sidebar/sidebar.js b/sidebar/sidebar.js
index ed6b39f..ccfd78c 100644
--- a/sidebar/sidebar.js
+++ b/sidebar/sidebar.js
@@ -2,24 +2,28 @@ const utils = require('../utils/utils.js');
var Promise = require('promise');
module.exports=
-{
- main: function(res)
{
- return new Promise(function(resolve, reject)
+ main: function(res)
{
- res.write("
");
-
- utils.include(res,"sidebar/sidebar.html").then(function()
- {
- return require("../sidebar/popularPosts.js").main(res);
- }).then(function()
+ return new Promise(function(resolve, reject)
{
- return require("../sidebar/categoriesSideBar.js").main(res);
- }).then(function()
- {
- res.write("
");
- resolve();
- });
- })
- }
-};
\ No newline at end of file
+ res.write("
");
+
+ utils.include(res,"sidebar/sidebar.html").then(function()
+ {
+ return require("../sidebar/popularPosts.js").main(res);
+ }).then(function()
+ {
+ return require("../sidebar/categoriesSideBar.js").main(res);
+ }).then(function()
+ {
+ res.write("
");
+ resolve();
+ }).catch(function(err)
+ {
+ console.log("hit error");
+ console.log(err);
+ })
+ })
+ }
+ };
\ No newline at end of file
diff --git a/utils/sql.js b/utils/sql.js
index 79a6b73..9e3295f 100644
--- a/utils/sql.js
+++ b/utils/sql.js
@@ -117,6 +117,11 @@ module.exports=
return fetch(q);
},
+ /**
+ * Function which currently returns all posts of a particular category from the database
+ * @param requestURL
+ * @return {*|Promise}
+ */
getPostsFromCategory: function(requestURL)
{
return new Promise(function(resolve, reject)
@@ -135,5 +140,36 @@ module.exports=
}
});
});
+ },
+
+ /**
+ * Helper method which returns a list of objects which contains the url and name of thee ten most recent posts
+ *
+ * {[name: , url: ],[name: , url: ],[name: , url: ],...}
+ *
+ * @return {*|Promise}
+ */
+ getRecentPosts: function()
+ {
+ return new Promise(function(resolve, reject)
+ {
+ var q = "select name, category_id from posts order by post_id desc limit 10";
+ fetch(q).then(function(sqlPosts)
+ {
+ var posts = [];
+ sqlPosts.forEach(function(p)
+ {
+ var getCategory = "select url from categories where category_id='" + p.category_id + "'";
+ fetch(getCategory).then(function(url)
+ {
+ var obj = new Object();
+ obj.name = p.name;
+ obj.category = url.url;
+ posts.push(obj);
+ })
+ });
+ resolve(posts);
+ });
+ });
}
};
\ No newline at end of file