From 5a2828c4dfd66e75de899080e461c3d482f152a0 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Fri, 5 Oct 2018 21:47:25 -0400 Subject: [PATCH] Added a very basic latex support for blog posts using pandoc. --- README.md | 3 +++ admin.js | 2 +- admin/admin.js | 1 + admin/category/addCategory.js | 2 +- admin/downloads/manageDownloads.js | 2 +- admin/login/login.js | 6 +++-- admin/posts/newPost.js | 2 +- ...ngFibonacci.md => everything-fibonacci.md} | 0 includes/html/contact.html | 2 ++ includes/html/header.html | 5 ++++ package.json | 2 +- posts/singlePost.js | 21 +++++++++++---- utils/markdownToHTML.js | 26 +++++++++++++++++++ utils/sql.js | 8 +++--- 14 files changed, 66 insertions(+), 16 deletions(-) rename blogContent/posts/programming/{EverythingFibonacci.md => everything-fibonacci.md} (100%) create mode 100644 utils/markdownToHTML.js diff --git a/README.md b/README.md index 1ca66b0..2ca504d 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,9 @@ npm install memory-cache --save npm install request npm install nodemailer npm install nodemailer-smtp-transport + + +npm install node-pandoc ``` diff --git a/admin.js b/admin.js index 574263a..ff986e5 100644 --- a/admin.js +++ b/admin.js @@ -67,7 +67,7 @@ app.use(function(request, result) const file = "./admin/admin.js"; Promise.all([includes.printAdminHeader(), - require(file).main(filename, request), + require(file).main(request), includes.printFooter()]).then(function(content) { result.write(content.join('')); diff --git a/admin/admin.js b/admin/admin.js index 57fe199..967086a 100644 --- a/admin/admin.js +++ b/admin/admin.js @@ -22,6 +22,7 @@ module.exports= { utils.getPostData(request).then(function (postData) { + console.log(postData); Promise.all([require("./posts/newPost.js").main(postData), require("./category/addCategory.js").main(postData), require("./posts/editPost.js").main(postData), diff --git a/admin/category/addCategory.js b/admin/category/addCategory.js index 3dfbfc5..d05fac9 100644 --- a/admin/category/addCategory.js +++ b/admin/category/addCategory.js @@ -81,7 +81,7 @@ module.exports= { return new Promise(function(resolve, reject) { - Promise.all([utils.include("./admin/addCategory.html"), + Promise.all([utils.include("./admin/category/addCategory.html"), printCategories(), processPost(postData)]).then(function(html) { diff --git a/admin/downloads/manageDownloads.js b/admin/downloads/manageDownloads.js index be0e02b..84ef742 100644 --- a/admin/downloads/manageDownloads.js +++ b/admin/downloads/manageDownloads.js @@ -57,7 +57,7 @@ const addDownload = function(postData) return new Promise(function(resolve, reject) { Promise.all([addDownloadPostData(postData), - utils.include("./admin/addDownload.html")]).then(function(html) + utils.include("./admin/downloads/addDownload.html")]).then(function(html) { resolve("
" + html.join('') + "
"); }).catch(function(error) diff --git a/admin/login/login.js b/admin/login/login.js index 1521579..71aafd9 100644 --- a/admin/login/login.js +++ b/admin/login/login.js @@ -22,6 +22,7 @@ const processLogin = function(request) return sql.checkLogin(postData); }).then(function(loginResult) { + if(loginResult.pass) { request.session.user = loginResult.user; @@ -30,7 +31,8 @@ const processLogin = function(request) } else { - resolve(""); + console.log("password incorrect"); + resolve("Password incorrect"); } }).catch(function(err) { @@ -52,7 +54,7 @@ module.exports= { return new Promise(function(resolve, reject) { - Promise.all([utils.include('./admin/login.html'), + Promise.all([utils.include("./admin/login/login.html"), require("../../sidebar/sidebar.js").main(), processLogin(request)]).then(function(html) { diff --git a/admin/posts/newPost.js b/admin/posts/newPost.js index 787eb0b..f0d2cc5 100644 --- a/admin/posts/newPost.js +++ b/admin/posts/newPost.js @@ -55,7 +55,7 @@ module.exports= { return new Promise(function(resolve, reject) { - Promise.all([utils.include("./admin/newPost.html"), processPost(postData)]).then(function(html) + Promise.all([utils.include("./admin/posts/newPost.html"), processPost(postData)]).then(function(html) { resolve(html.join('')); }).catch(function(error) diff --git a/blogContent/posts/programming/EverythingFibonacci.md b/blogContent/posts/programming/everything-fibonacci.md similarity index 100% rename from blogContent/posts/programming/EverythingFibonacci.md rename to blogContent/posts/programming/everything-fibonacci.md diff --git a/includes/html/contact.html b/includes/html/contact.html index 12f5f3c..9efa102 100644 --- a/includes/html/contact.html +++ b/includes/html/contact.html @@ -51,6 +51,8 @@ +
+
diff --git a/includes/html/header.html b/includes/html/header.html index 873c01d..db302d4 100644 --- a/includes/html/header.html +++ b/includes/html/header.html @@ -25,6 +25,11 @@ } p{font-size:18px;} + + + + + diff --git a/package.json b/package.json index 03375c9..802a1d6 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,9 @@ "highlight": "^0.2.4", "highlight.js": "^9.12.0", "markdown": "^0.5.0", - "markdown-to-html": "^0.0.13", "memory-cache": "^0.2.0", "mysql": "^2.16.0", + "node-pandoc": "^0.3.0", "nodemailer": "^4.6.8", "nodemailer-smtp-transport": "^2.7.4", "promise": "^8.0.1", diff --git a/posts/singlePost.js b/posts/singlePost.js index d31b557..04dc292 100644 --- a/posts/singlePost.js +++ b/posts/singlePost.js @@ -5,6 +5,8 @@ const sql = require('../utils/sql'); const Remarkable = require('remarkable'); const hljs = require('highlight.js'); +const pandoc = require('../utils/markdownToHTML.js'); + const md = new Remarkable( { @@ -143,13 +145,22 @@ module.exports= var markDown = utils.getFileContents(pathName).toString(); markDown = markDown.split("(media/").join("(" + "../blogContent/posts/" + category[0].url + "/media/"); - html += md.render(markDown); + //html += md.render(markDown); + + pandoc.convertToHTML(markDown).then(function(result) + { + html +=result; + + html = html.split("").join(""); + html += "

"; - html = html.split("").join(""); - html += "

"; + resolve(htmlHead + html); + }).catch(function(error) + { + reject(error); + }) - resolve(htmlHead + html); }); } catch(ex) diff --git a/utils/markdownToHTML.js b/utils/markdownToHTML.js new file mode 100644 index 0000000..f2c9567 --- /dev/null +++ b/utils/markdownToHTML.js @@ -0,0 +1,26 @@ +const pandoc = require('node-pandoc'); +// const args = '-t html5'; + +const args = '-S --base-header-level=1 --toc --toc-depth=6 -N --normalize -s --mathjax -t html5'; + +console.log(""); +module.exports= + { + convertToHTML: function(markdownContents) + { + return new Promise(function(resolve, reject) + { + // Set your callback function + callback = function (err, result) + { + if (err) + { + reject(err); + } + resolve(result); + }; + console.log(markdownContents); + pandoc(markdownContents, args, callback); + }); + }, + } diff --git a/utils/sql.js b/utils/sql.js index 336fe97..fb86cf5 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -268,16 +268,16 @@ module.exports= if(post.username && post.password) { - var cleanName = sanitizer.sanitize(post.username); - var cleanPassword = sanitizer.sanitize(post.password); + const cleanName = sanitizer.sanitize(post.username); + const cleanPassword = sanitizer.sanitize(post.password); - var getSalt = "select * from users where user_name='" + + const getSalt = "select * from users where user_name='" + cleanName + "'"; fetch(getSalt).then(function(saltResult) { if(saltResult.length == 1) { - var hashedPassword = crypto.createHash('sha256') + const hashedPassword = crypto.createHash('sha256') .update(cleanPassword + saltResult[0].salt) .digest('hex'); if(saltResult[0].password === hashedPassword)