diff --git a/README.md b/README.md
index b2d6dfa..c6a115c 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,7 @@ category_id mediumint unsigned not null,
picture_url varchar(100) not null,
published datetime not null,
name varchar(100) not null,
+url varchar(100) not null,
primary key(post_id)
);
@@ -50,4 +51,5 @@ grant all on blog_name.* to blog_user@localhost identified by "password";
npm install mysql
npm install sanitizer
npm install promise
+npm install markdown
```
diff --git a/admin/newPost.js b/admin/newPost.js
index 9ba8100..ab96b4e 100644
--- a/admin/newPost.js
+++ b/admin/newPost.js
@@ -7,11 +7,23 @@ var Promise = require('promise');
module.exports=
{
+ /**
+ *
+ * @param res
+ * @param postData
+ * @return {*}
+ */
main: function(res, postData)
{
utils.include(res, "./admin/newPost.html");
return this.processPost(res, postData);
},
+ /**
+ *
+ * @param res
+ * @param postData
+ * @return {*|Promise}
+ */
processPost: function(res, postData)
{
return new Promise(function(resolve, reject)
@@ -19,9 +31,24 @@ module.exports=
var post = qs.parse(postData);
if(post.add_post_name)
{
+ var urls = post.add_post_name;
+ urls = urls.split(" ").join("-");
+ urls =urls.toLowerCase();
+
+ var q = "insert into posts (category_id, picture_url, published, name, url) values ";
+
+ q += "('" + post.add_post_category + "', '" + post.add_post_picture +
+ "', '" + post.add_post_date + "', '" + post.add_post_name + "', '" + urls + "')";
+ sql.insert(q).then(function()
+ {
+ resolve();
+ })
+ }
+ else
+ {
+ resolve(postData);
}
- resolve(postData);
});
}
};
\ No newline at end of file
diff --git a/entries/testing-my-server.md b/entries/testing-my-server.md
new file mode 100644
index 0000000..f5d2cf5
--- /dev/null
+++ b/entries/testing-my-server.md
@@ -0,0 +1,8 @@
+#THIS IS A H1
+
+This page is merely for testing -- go away
+
+
+```javascript
+var i = 1;
+```
\ No newline at end of file
diff --git a/posts/singlePost.js b/posts/singlePost.js
index cd71019..154025a 100644
--- a/posts/singlePost.js
+++ b/posts/singlePost.js
@@ -2,6 +2,8 @@ const utils = require('../utils/utils.js');
var Promise = require('promise');
+var markdown = require( "markdown" ).markdown;
+
module.exports=
{
/**
@@ -25,11 +27,20 @@ module.exports=
res.write("");
res.write("
");
- //include page content
- utils.include(res, "../entries/" + post.url + ".html").then(function (value) {
- res.write("
");
- resolve();
- });
+
+ var pathName = "entries/" + post.url + ".md";
+ try
+ {
+ res.write(markdown.toHTML(utils.getFileContents(pathName)));
+ }
+ catch(ex)
+ {
+ console.log(ex);
+ //utils.include(res, "includes/404.html");
+ }
+
+ res.write("");
+ resolve()
});
}
};
diff --git a/utils/sql.js b/utils/sql.js
index 11e9adb..b81a46f 100644
--- a/utils/sql.js
+++ b/utils/sql.js
@@ -24,7 +24,7 @@ con.connect(function(err) {
*/
var fetch = function(sqlStatement)
{
- console.log("sql fetch method called");
+ console.log("sql fetch method called with + " + sqlStatement);
return new Promise(function(resolve, reject)
{
con.query(sqlStatement, function (err, result)
@@ -38,7 +38,6 @@ var fetch = function(sqlStatement)
resolve(result);
});
});
-
};
module.exports=
@@ -53,15 +52,19 @@ module.exports=
*/
insert : function(sqlStatement)
{
- con.query((sqlStatement), function (err, result)
+ return new Promise(function(resolve, reject)
{
- if (err)
+ con.query(sanitizer.sanitize(sqlStatement), function (err, result)
{
- console.log(err);
- return 0;
- }
- return result.insertId;
- });
+ if (err)
+ {
+ console.log(err);
+ resolve(0);
+ }
+ console.log(sqlStatement);
+ resolve(result.insertId);
+ });
+ })
},
/**
@@ -75,19 +78,19 @@ module.exports=
{
return new Promise(function(resolve, reject)
{
- var splitURL = requestURL.split("/");
+ var splitURL = requestURL.split("/")
var q = "select * from categories where url='" + splitURL[1] + "'";
+
fetch(q).then(function (result_category)
{
- console.log(result_category);
if(result_category.length != 0)
{
- q = "select * from posts where category_id='" + result_category[0].category_id + "' and url='" + splitURL[2] + "'";
- console.log(q);
- fetch(q).then(function (result_posts)
+ var q2 = "select * from posts where category_id='" + result_category[0].category_id +
+ "' and url='" + splitURL[2] + "'";
+
+ fetch(q2).then(function (result_posts)
{
- console.log(result_posts);
if(result_posts != 0)
{
resolve(result_posts[0]);
@@ -112,7 +115,7 @@ module.exports=
*
* @return {Promise | * | Array}
*/
- getCategories: function()
+ getCategories : function()
{
var q = "select * from categories";
return fetch(q);
diff --git a/utils/utils.js b/utils/utils.js
index d6ad60d..ebffd85 100644
--- a/utils/utils.js
+++ b/utils/utils.js
@@ -32,6 +32,20 @@ module.exports=
});
},
+ getFileContents: function(fileName)
+ {
+ try
+ {
+ return write(fs.readFileSync(fileName));
+ }
+ catch (e)
+ {
+ console.log("Could not find " + fileName);
+ }
+ return 0;
+ },
+
+
/**
* Function which is responsible for returning all post data.
*