diff --git a/entries/programs/media/90e4464eb85c998c8db42c965468aa54.png b/entries/programs/media/90e4464eb85c998c8db42c965468aa54.png index d79cea2..89c4aa5 100644 Binary files a/entries/programs/media/90e4464eb85c998c8db42c965468aa54.png and b/entries/programs/media/90e4464eb85c998c8db42c965468aa54.png differ diff --git a/entries/projects/media/088cc48e754c1b99e0fcd5a5eddb9d64.png b/entries/projects/media/088cc48e754c1b99e0fcd5a5eddb9d64.png index 516fbbf..4980076 100644 Binary files a/entries/projects/media/088cc48e754c1b99e0fcd5a5eddb9d64.png and b/entries/projects/media/088cc48e754c1b99e0fcd5a5eddb9d64.png differ diff --git a/entries/projects/media/161edc628257e8a2f92086c5987dcf0f.png b/entries/projects/media/161edc628257e8a2f92086c5987dcf0f.png index 69a97b3..9021dbc 100644 Binary files a/entries/projects/media/161edc628257e8a2f92086c5987dcf0f.png and b/entries/projects/media/161edc628257e8a2f92086c5987dcf0f.png differ diff --git a/entries/projects/media/fc0a0ddf2a914b171bb3a5013e9e7b6c.png b/entries/projects/media/fc0a0ddf2a914b171bb3a5013e9e7b6c.png index 778b8df..7586e75 100644 Binary files a/entries/projects/media/fc0a0ddf2a914b171bb3a5013e9e7b6c.png and b/entries/projects/media/fc0a0ddf2a914b171bb3a5013e9e7b6c.png differ diff --git a/entries/projects/media/steam/ben2.png b/entries/projects/media/steam/ben2.png index 32d2d15..2296651 100644 Binary files a/entries/projects/media/steam/ben2.png and b/entries/projects/media/steam/ben2.png differ diff --git a/entries/projects/media/steam/diagram.png b/entries/projects/media/steam/diagram.png index 7562149..5ff7b7a 100644 Binary files a/entries/projects/media/steam/diagram.png and b/entries/projects/media/steam/diagram.png differ diff --git a/entries/projects/media/steam/jrtechs2.png b/entries/projects/media/steam/jrtechs2.png index 2016a56..1b35776 100644 Binary files a/entries/projects/media/steam/jrtechs2.png and b/entries/projects/media/steam/jrtechs2.png differ diff --git a/img/image.js b/img/image.js index 12de61e..b2da529 100644 --- a/img/image.js +++ b/img/image.js @@ -10,7 +10,10 @@ module.exports= main: function(result, fileName) { result.contentType = 'image/png'; - utils.include(result, "." + fileName); - result.end(); + utils.include("." + fileName).then(function(content) + { + result.write(content); + result.end(); + }); } }; \ No newline at end of file diff --git a/includes/includes.js b/includes/includes.js index 7bf2571..640685d 100644 --- a/includes/includes.js +++ b/includes/includes.js @@ -18,30 +18,28 @@ module.exports = * @param result * @return {*} a promise retrieved from the utils.include function */ - printHeader: function(result) + printHeader: function() { - result.writeHead(200, {'Content-Type': 'text/html'}); - return utils.include(result, HEADER_FILE); + // utils.getFileContents(HEADER_FILE); + return utils.include(HEADER_FILE); }, + + /** * Appends the footer to the result object * - * @param result * @return {*|Promise} */ - printFooter: function(result) + printFooter: function() { - return new Promise(function(resolve, reject) - { - utils.include(result, FOOTER_FILE).then(function() - { - result.end(); - resolve(); - }) - - }) + return utils.include(FOOTER_FILE); + // return new Promise(function(resolve, reject) + // { + // resolve(utils.getFileContents(FOOTER_FILE)); + // }) }, + /**Sends a css file to the user * * @param result @@ -51,7 +49,14 @@ module.exports = sendCSS: function(result, path) { result.writeHead(200, {'Content-Type': 'text/css'}); - utils.include(result, "./" + path); - result.end(); + utils.include("./" + path).then(function(content) + { + result.write(content); + result.end(); + }).catch(function(error) + { + console.log(error); + }); + } }; \ No newline at end of file diff --git a/posts/homePage.js b/posts/homePage.js index 4029562..948fc28 100644 --- a/posts/homePage.js +++ b/posts/homePage.js @@ -11,21 +11,22 @@ const postRenderer = require('../posts/singlePost.js'); * @param result * @returns {*|Promise} */ -var renderRecentPosts = function(result) +var renderRecentPosts = function() { return new Promise(function(resolve, reject) { + console.log("recent post render page"); sql.getRecentPostSQL().then(function(posts) { var postPromises = []; - result.write("
"); + var content = "
"; posts.forEach(function(post) { postPromises.push(new Promise(function(res, rej) { - postRenderer.renderPreview(result, post).then(function() + postRenderer.renderPreview(post).then(function(cont) { - res(); + res(cont); }).catch(function(error) { rej(error); @@ -33,17 +34,16 @@ var renderRecentPosts = function(result) })); }); - Promise.all(postPromises).then(function() + Promise.all(postPromises).then(function(cont) { - result.write("
"); - resolve(); + content = content + cont.join('') + "
"; + resolve(content); }).catch(function(error) { reject(error); }) }).catch(function(error) { - console.log(error); reject(error); }) }); @@ -57,22 +57,32 @@ module.exports= * @param res * @param fileName request url */ - main: function(result, requestURL, request) + main: function(requestURL, request) { return new Promise(function(resolve, reject) { + // renderRecentPosts().then(function() + // { + // return require("../sidebar/sidebar.js").main(); + // }).then(function() + // { + // resolve(); + // }).catch(function(error) + // { + // console.log(error); + // reject(error); + // }) - renderRecentPosts(result).then(function() - { - return require("../sidebar/sidebar.js").main(result); - }).then(function() + + console.log("home page"); + Promise.all([renderRecentPosts(), require("../sidebar/sidebar.js").main()]).then(function(content) { - resolve(); + console.log("fin posts"); + resolve(content.join('')); }).catch(function(error) { - console.log(error); reject(error); - }) + }); }) } }; \ No newline at end of file diff --git a/posts/singlePost.js b/posts/singlePost.js index 3eb0535..2c4aa14 100644 --- a/posts/singlePost.js +++ b/posts/singlePost.js @@ -36,7 +36,7 @@ module.exports= * @param res * @param post */ - renderPreview: function(res, post) + renderPreview: function(post) { return new Promise(function(resolve, reject) { @@ -88,9 +88,8 @@ module.exports= " \n"; html += "

"; - res.write(html); - resolve() + resolve(html) }).catch(function(error) { console.log(error); @@ -100,7 +99,6 @@ module.exports= catch(ex) { reject(ex); - console.log(ex); } }); }, @@ -112,7 +110,7 @@ module.exports= * @param post sql data about the blog post * @return {*|Promise} */ - renderPost: function(res, post) + renderPost: function(post) { return new Promise(function (resolve, reject) { @@ -148,14 +146,12 @@ module.exports= html += "

"; - res.write(html); - resolve() + resolve(html); }); } catch(ex) { - //console.log(ex); - //utils.include(res, "includes/404.html"); + reject(ex); } }); } diff --git a/server.js b/server.js index 6a64e51..7efaa13 100644 --- a/server.js +++ b/server.js @@ -9,22 +9,22 @@ const http = require('http'); const url = require('url'); -var express = require("express"); +const express = require("express"); -var session = require('express-session'); +const session = require('express-session'); const includes = require('./includes/includes.js'); const utils = require('./utils/utils.js'); -var map = require('./utils/generateSiteMap.js'); +const map = require('./utils/generateSiteMap.js'); map.main(); -var app = express(); +const app = express(); app.use(session({ secret: utils.getFileLine('../session_secret'), cookie: { maxAge: 6000000 }})); -var port = 8000; +const port = 8000; /** @@ -76,16 +76,31 @@ app.use(function(request, res) file = "./posts/posts.js"; } - includes.printHeader(res).then(function() + // includes.printHeader(res).then(function() + // { + // return require(file).main(res, filename, request); + // }).then(function() + // { + // return includes.printFooter(res); + // }).catch(function(err) + // { + // console.log(err); + // }) + + res.writeHead(200, {'Content-Type': 'text/html'}); + + Promise.all([includes.printHeader(), + require(file).main(filename, request), + includes.printFooter()]).then(function(content) { - return require(file).main(res, filename, request); - }).then(function() - { - return includes.printFooter(res); + console.log("main fin"); + res.write(content.join('')); + res.end(); }).catch(function(err) { console.log(err); - }) + }); + } } else diff --git a/sidebar/categoriesSideBar.js b/sidebar/categoriesSideBar.js index 1e531ae..8ee3968 100644 --- a/sidebar/categoriesSideBar.js +++ b/sidebar/categoriesSideBar.js @@ -10,33 +10,30 @@ module.exports= * @param res * @return {*|Promise} */ - main: function(res) + main: function() { return new Promise(function(resolve, reject) { - res.write("

"); + var content = "

"; - //res.write("

Categories

"); + content += "
"; - //res.write("

Categories

"); - - //res.write("
"); - res.write("
"); - - res.write(" \n" + + content += " \n" + "
Categories
\n" + - "
"); + " "; sql.getCategories().then(function(categories) { categories.forEach(function(cat) { - //res.write(cat.name); - res.write("" + cat.name + "
"); + content += "" + cat.name + "
"; }); - res.write("

"); - resolve(); - }) + content += "

"; + resolve(content); + }).catch(function(error) + { + reject(error); + }); }); } }; diff --git a/sidebar/recentPosts.js b/sidebar/recentPosts.js index 4b60e96..308baad 100644 --- a/sidebar/recentPosts.js +++ b/sidebar/recentPosts.js @@ -5,35 +5,38 @@ module.exports= { /** Renders the the recent post sidebar. * - * @param res * @returns {*|Promise} */ - main: function(res) + main: function() { return new Promise(function(resolve, reject) { - res.write("
"); + console.log("recent page"); - // res.write("
" + - // "

Recent Posts

"); - res.write("
"); + var content = "
"; - res.write(" \n" + + + content +="
"; + + content +=" \n" + "
Recent Posts
\n" + - "
"); + " "; sql.getRecentPosts().then(function(posts) { posts.forEach(function(p) { var url = '/' + p.category + '/' + p.url; - res.write("" + p.name + "
"); + content += "" + p.name + "
"; }); - res.write("
"); - resolve(); + content +="
"; + resolve(content); + }).catch(function(error) + { + reject(error); }) }); } diff --git a/sidebar/sidebar.js b/sidebar/sidebar.js index 82fa2a4..378e11b 100644 --- a/sidebar/sidebar.js +++ b/sidebar/sidebar.js @@ -1,5 +1,5 @@ const utils = require('../utils/utils.js'); -var Promise = require('promise'); +const Promise = require('promise'); module.exports= { @@ -9,28 +9,40 @@ module.exports= * @param res * @returns {*|Promise} */ - main: function(res) + main: function() { return new Promise(function(resolve, reject) { - res.write("
"); + console.log("sidebar page"); - utils.include(res,"sidebar/sidebar.html").then(function() - { - return require("../sidebar/recentPosts.js").main(res); - }).then(function() - { - return require("../sidebar/categoriesSideBar.js") - .main(res); - }).then(function() + // res.write("
"); + // + // utils.include(res,"sidebar/sidebar.html").then(function() + // { + // return require("../sidebar/recentPosts.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); + // }) + + Promise.all([utils.include("sidebar/sidebar.html"), + require("../sidebar/recentPosts.js").main(), + require("../sidebar/categoriesSideBar.js").main()]).then(function(content) { - res.write("
"); - resolve(); - }).catch(function(err) + resolve("
" + content.join('') + "
"); + }).catch(function(error) { - console.log("hit error"); - console.log(err); - }) + reject(error); + }); }) } }; \ No newline at end of file diff --git a/utils/utils.js b/utils/utils.js index d2e2e93..de4e2f1 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -13,22 +13,22 @@ module.exports= * A function similar to the include statement in PHP * This function writes a file to the output * - * @param result the result that is sent to the user from node * @param fileName the file to append to the result */ - include: function(result, fileName) + include: function(fileName) { return new Promise(function(resolve, reject) { try { - result.write(fs.readFileSync(fileName)); + resolve(fs.readFileSync(fileName)); + } catch (e) { console.log("Could not find " + fileName); + resolve(""); } - resolve(); }); },