diff --git a/entries/testing-my-server.md b/entries/testing-my-server.md index e6a217e..d0115db 100644 --- a/entries/testing-my-server.md +++ b/entries/testing-my-server.md @@ -3,33 +3,12 @@ This page is merely for testing -- go away ``` -include -void main(int argc, char * argv[]) -{ - int vals[1000]; - - //value will overflow a 32 bit int!!! - long int max = 0; - - char * data = argv[1]; - for(int i = 0; i < 1000; i++) - { - vals[i] = (int)data[i] - 48; - } +int i = 0; +``` - for(int i = 0; i < 1000 - 13; i ++) - { - long int tempMax = 1; - for(int t = i; t < i + 13; t++) - { - tempMax *= vals[t]; - } - if(tempMax > max) - { - max = tempMax; - } - } +##This is a h2 - printf("the max number is %ld", max); -} -``` \ No newline at end of file +``` +python3 roosay.py +``` +This is just to test what a paragraph looks like. \ No newline at end of file diff --git a/includes/header.html b/includes/header.html index 47bf5a7..b009c90 100644 --- a/includes/header.html +++ b/includes/header.html @@ -28,9 +28,9 @@
diff --git a/posts/category.js b/posts/category.js index 32f3a60..10ce9c1 100644 --- a/posts/category.js +++ b/posts/category.js @@ -1,13 +1,61 @@ var Promise = require('promise'); const sql = require('../utils/sql'); +const utils = require('../utils/utils.js'); -module.exports= +var renderPosts = function(result, resultURL) { - main: function(res, fileName) + var splitURL = resultURL.split("/"); + if(splitURL.length >= 3) { + result.write("
\n"); + return new Promise(function(resolve, reject) { - resolve(); + sql.getPostsFromCategory(splitURL[2]).then(function(posts) + { + posts.forEach(function(p) + { + + require("../posts/singlePost.js").renderPost(result, p); + }); + }).then(function() + { + result.write("
"); + resolve(); + }) }); } -}; \ No newline at end of file + else + { + return utils.print404(result); + } +}; + +module.exports= + { + renderPostPreview: function(result, postSQLData) + { + + }, + + /** + * Calls posts and sidebar modules to render blog contents in order + * + * @param res + * @param fileName request url + */ + main: function(res, requestURL, request) + { + console.log("category page"); + return new Promise(function(resolve, reject) + { + renderPosts(res, requestURL).then(function() + { + return require("../sidebar/sidebar.js").main(res) + }).then(function () + { + resolve(); + }) + }); + } + } \ No newline at end of file diff --git a/posts/posts.js b/posts/posts.js index 57a4c4e..ecd6f1a 100644 --- a/posts/posts.js +++ b/posts/posts.js @@ -29,7 +29,7 @@ var renderPost = function(res, requestURL) } else { - return utils.include(res, "includes/404.html"); + return utils.print404(res); } }).then(function() { @@ -54,6 +54,7 @@ module.exports= */ main: function(res, requestURL, request) { + console.log("posts page"); return new Promise(function(resolve, reject) { renderPost(res, requestURL).then(function() diff --git a/posts/singlePost.js b/posts/singlePost.js index 96d99e0..d197497 100644 --- a/posts/singlePost.js +++ b/posts/singlePost.js @@ -4,9 +4,6 @@ var Promise = require('promise'); var markdown = require( "markdown" ).markdown; -var Markdown = require('markdown-to-html').Markdown; -var md = new Markdown(); - module.exports= { @@ -23,6 +20,8 @@ module.exports= { res.write("
"); //image + res.write("\"Nature\""); + res.write("
"); //title res.write("

" + post.name + "

"); diff --git a/server.js b/server.js index 80cb281..9cc849a 100644 --- a/server.js +++ b/server.js @@ -29,8 +29,8 @@ http.createServer(function (request, res) { var file = ""; - if(filename.includes("/category")) //single category page - file = "../posts/category.js"; + if(filename.includes("/categories/")) //single category page + file = "./posts/category.js"; else if(filename.includes("/admin")) //top secret admin page file = "./admin/admin.js"; @@ -38,6 +38,8 @@ http.createServer(function (request, res) else //single post page file = "./posts/posts.js"; + console.log(file); + includes.printHeader(res).then(function() { return require(file).main(res, filename, request); diff --git a/utils/sql.js b/utils/sql.js index 8739553..79a6b73 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -115,5 +115,25 @@ module.exports= { var q = "select * from categories"; return fetch(q); + }, + + getPostsFromCategory: function(requestURL) + { + return new Promise(function(resolve, reject) + { + var q = "select * from categories where name ='" + requestURL + "' limit 1"; + fetch(q).then(function(categories) + { + if(categories.length != 0) + { + var qPosts = "select * from posts where category_id='" + categories[0].category_id + "'"; + resolve(fetch(qPosts)); + } + else + { + resolve(0); + } + }); + }); } }; \ No newline at end of file diff --git a/utils/utils.js b/utils/utils.js index 92c4bbd..f139d8f 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -85,5 +85,10 @@ module.exports= resolve(0); } }); + }, + + print404: function(result) + { + return this.include(result, "includes/404.html"); } }; \ No newline at end of file