Browse Source

Fixed last minute bugs

pull/4/head
jrtechs 6 years ago
parent
commit
d99ebe4d22
7 changed files with 38 additions and 22 deletions
  1. +0
    -0
      entries/Java/testing-my-server.md
  2. +1
    -3
      posts/category.js
  3. +11
    -13
      posts/singlePost.js
  4. +2
    -3
      server.js
  5. +3
    -1
      sidebar/sidebar.html
  6. +3
    -2
      utils/sql.js
  7. +18
    -0
      utils/utils.js

entries/testing-my-server.md → entries/Java/testing-my-server.md View File


+ 1
- 3
posts/category.js View File

@ -21,8 +21,7 @@ var renderPosts = function(result, resultURL)
promises.push(new Promise(function(res, rej)
{
require("../posts/singlePost.js")
.renderPost(result, p)
.then(function()
.renderPost(result, p).then(function()
{
res();
});
@ -60,7 +59,6 @@ module.exports=
*/
main: function(res, requestURL, request)
{
console.log("category page");
return new Promise(function(resolve, reject)
{
renderPosts(res, requestURL).then(function()

+ 11
- 13
posts/singlePost.js View File

@ -20,37 +20,35 @@ module.exports=
{
return new Promise(function (resolve, reject)
{
res.write("<div class=\"w3-card-4 w3-margin w3-white\">");
var html = "<div class=\"w3-card-4 w3-margin w3-white\">";
//image
if(!(post.picture_url ==="n/a"))
if(!(post.picture_url === "n/a"))
{
res.write("<img src=\"/img/posts/" + post.picture_url + "\" alt=\"Nature\" style=\"width:100%\">");
html +="<img src=\"/img/posts/" + post.picture_url + "\" alt=\"Nature\" style=\"width:100%\">";
}
res.write("<div class=\"w3-container\">");
html += "<div class=\"w3-container\">";
//title
res.write("<h3><b>" + post.name + "</b></h3>");
html += "<h3><b>" + post.name + "</b></h3>";
//date
res.write("<h5><span class=\"w3-opacity\">" + post.published.toDateString() + "</span></h5>");
res.write("</div>");
html += "<h5><span class=\"w3-opacity\">" + post.published.toDateString() + "</span></h5>";
html +="</div>";
res.write("<div class=\"w3-container\">");
html += "<div class=\"w3-container\">";
try
{
sql.getCategory(post.category_id).then(function(category)
{
var pathName = "entries/" + category.url + "/" + post.url + ".md";
var html = markdown.toHTML(utils.getFileContents(pathName).toString());
var pathName = "entries/" + category[0].url + "/" + post.url + ".md";
html += markdown.toHTML(utils.getFileContents(pathName).toString());
html = html.split("<code>").join("<pre><code>");
html = html.split("</code>").join("</code></pre>");
html = html.split("\\`\\`\\`").join("```");
html = html.split("![](media/").join("![](" + "entries/" + category.url + "/media/");
html += "</div></div>";
res.write(html);
res.write("</div></div>");
resolve()
});
}

+ 2
- 3
server.js View File

@ -33,8 +33,7 @@ var app = express();
// cert: cert,
// ca: ca
// };
app.use(session({ secret: utils.getFileContents('../../session_secret'), cookie: { maxAge: 6000000 }}));
app.use(session({ secret: utils.getFileLine('../session_secret'), cookie: { maxAge: 6000000 }}));
app.use(function(request, res)
{
@ -55,7 +54,7 @@ app.use(function(request, res)
var file = "";
if(filename === '' || filename === '/')
filename = '/category/projects';
filename = '/category/Java';
var urlSplit = filename.split("/");

+ 3
- 1
sidebar/sidebar.html View File

@ -1,3 +1,4 @@
<!--
<div class="w3-card w3-margin w3-margin-top">
<div class="w3-container w3-white">
@ -8,4 +9,5 @@
</div>
</div><hr>
</div><hr>
-->

+ 3
- 2
utils/sql.js View File

@ -10,13 +10,14 @@ const qs = require('querystring');
const utils = require('../utils/utils.js');
const con = mysql.createConnection({
var con = mysql.createConnection({
host: "localhost",
user: "blog_user",
password: utils.getFileContents('../../sql_secret'),
password: utils.getFileLine('../sql_secret'),
database: "blog_name"
});
con.connect(function(err) {
if (err) throw err;
});

+ 18
- 0
utils/utils.js View File

@ -50,6 +50,24 @@ module.exports=
return 0;
},
/**
*
* @param fileName
* @return {*}
*/
getFileLine: function(fileName)
{
try
{
return fs.readFileSync(fileName, "utf8").split('\n').join('');
}
catch (e)
{
console.log("Could not find " + fileName);
}
return 0;
},
/**
* Function which is responsible for returning all post data.

Loading…
Cancel
Save