Browse Source

Finalized changes for initial test deployment

pull/4/head
jrtechs 6 years ago
parent
commit
ab69af1bdc
6 changed files with 54 additions and 21 deletions
  1. +1
    -0
      README.md
  2. +2
    -2
      includes/footer.html
  3. +0
    -2
      posts/category.js
  4. +20
    -9
      posts/singlePost.js
  5. +24
    -4
      server.js
  6. +7
    -4
      utils/sql.js

+ 1
- 0
README.md View File

@ -54,4 +54,5 @@ npm install markdown
npm install markdown-to-html -g npm install markdown-to-html -g
npm install highlight npm install highlight
npm install crypto npm install crypto
npm i express-force-ssl
``` ```

+ 2
- 2
includes/footer.html View File

@ -18,10 +18,10 @@
</div> </div>
</div> </div>
<div class="w3-center">Copyright &copy; Jrtechs.net 2018</div>
<div class="w3-center">Copyright &copy; <a href="https://jrtechs.net">Jrtechs.net</a> 2018</div>
</footer> </footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad(); console.log("yikes");</script>
<script>hljs.initHighlightingOnLoad();</script>
</body> </body>

+ 0
- 2
posts/category.js View File

@ -16,8 +16,6 @@ var renderPosts = function(result, resultURL)
sql.getPostsFromCategory(splitURL[2]).then(function(posts) sql.getPostsFromCategory(splitURL[2]).then(function(posts)
{ {
var promises = []; var promises = [];
console.log(posts);
console.log("^^^^");
posts.forEach(function(p) posts.forEach(function(p)
{ {
promises.push(new Promise(function(res, rej) promises.push(new Promise(function(res, rej)

+ 20
- 9
posts/singlePost.js View File

@ -4,6 +4,8 @@ var Promise = require('promise');
var markdown = require( "markdown" ).markdown; var markdown = require( "markdown" ).markdown;
const sql = require('../utils/sql');
module.exports= module.exports=
{ {
@ -20,7 +22,10 @@ module.exports=
{ {
res.write("<div class=\"w3-card-4 w3-margin w3-white\">"); res.write("<div class=\"w3-card-4 w3-margin w3-white\">");
//image //image
res.write("<img src=\"https://www.w3schools.com/w3images/woods.jpg\" alt=\"Nature\" style=\"width:100%\">");
if(!(post.picture_url ==="n/a"))
{
res.write("<img src=\"/img/posts/" + post.picture_url + "\" alt=\"Nature\" style=\"width:100%\">");
}
res.write("<div class=\"w3-container\">"); res.write("<div class=\"w3-container\">");
//title //title
@ -31,23 +36,29 @@ module.exports=
res.write("<div class=\"w3-container\">"); res.write("<div class=\"w3-container\">");
var pathName = "entries/" + post.url + ".md";
try try
{ {
var html = markdown.toHTML(utils.getFileContents(pathName).toString());
sql.getCategory(post.category_id).then(function(category)
{
var pathName = "entries/" + category.url + "/" + post.url + ".md";
html = html.split("<code>").join("<pre><code>");
html = html.split("</code>").join("</code></pre>");
res.write(html);
var 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/");
res.write(html);
res.write("</div></div>");
resolve()
});
} }
catch(ex) catch(ex)
{ {
//console.log(ex); //console.log(ex);
//utils.include(res, "includes/404.html"); //utils.include(res, "includes/404.html");
} }
res.write("</div></div>");
resolve()
}); });
} }
}; };

+ 24
- 4
server.js View File

@ -7,6 +7,8 @@
const http = require('http'); const http = require('http');
var https = require('https');
const url = require('url'); const url = require('url');
var express = require("express"); var express = require("express");
@ -15,8 +17,23 @@ var session = require('express-session');
const includes = require('./includes/includes.js'); const includes = require('./includes/includes.js');
var forceSsl = require('express-force-ssl');
var app = express(); var app = express();
var fs = require('fs');
//var key = fs.readFileSync('private.key');
//var cert = fs.readFileSync( 'primary.crt' );
//var ca = fs.readFileSync( 'encryption/intermediate.crt' );
// var options = {
// key: key,
// cert: cert,
// ca: ca
// };
//the secret is different on production
app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 6000000 }})); app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 6000000 }}));
app.use(function(request, res) app.use(function(request, res)
@ -25,7 +42,7 @@ app.use(function(request, res)
var filename = q.pathname; var filename = q.pathname;
//handles image requests //handles image requests
if(filename.includes("/img/"))
if(filename.includes("/img/") || filename.includes(".jpg"))
{ {
require("./img/image.js").main(res, filename); require("./img/image.js").main(res, filename);
} }
@ -38,7 +55,7 @@ app.use(function(request, res)
var file = ""; var file = "";
if(filename === '' || filename === '/') if(filename === '' || filename === '/')
filename = '/category/Java';
filename = '/category/projects';
var urlSplit = filename.split("/"); var urlSplit = filename.split("/");
@ -62,7 +79,10 @@ app.use(function(request, res)
//console.log("fin"); //for debugging //console.log("fin"); //for debugging
}) })
} }
}); });
http.createServer(app).listen(8080);
//https.createServer(options, app).listen(443);
http.createServer(app).listen(80);
//app.use(forceSsl);

+ 7
- 4
utils/sql.js View File

@ -11,7 +11,7 @@ const qs = require('querystring');
const con = mysql.createConnection({ const con = mysql.createConnection({
host: "localhost", host: "localhost",
user: "blog_user", user: "blog_user",
password: "password",
password: "password", //definitely not the password on production
database: "blog_name" database: "blog_name"
}); });
@ -31,7 +31,7 @@ var fetch = function(sqlStatement)
{ {
con.query(sqlStatement, function (err, result) con.query(sqlStatement, function (err, result)
{ {
if (err)
if(err)
{ {
reject(); reject();
} }
@ -130,13 +130,11 @@ module.exports=
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
var q = "select * from categories where name ='" + requestURL + "' limit 1"; var q = "select * from categories where name ='" + requestURL + "' limit 1";
console.log(q);
fetch(q).then(function(categories) fetch(q).then(function(categories)
{ {
if(categories.length != 0) if(categories.length != 0)
{ {
var qPosts = "select * from posts where category_id='" + categories[0].category_id + "'"; var qPosts = "select * from posts where category_id='" + categories[0].category_id + "'";
console.log(qPosts);
resolve(fetch(qPosts)); resolve(fetch(qPosts));
} }
else else
@ -251,5 +249,10 @@ module.exports=
resolve(result); resolve(result);
} }
}); });
},
getCategory: function(categoryId)
{
return fetch("select * from categories where category_id='" + categoryId + "'");
} }
}; };

Loading…
Cancel
Save