Browse Source

Added a very basic latex support for blog posts using pandoc.

pull/3/head
jrtechs 6 years ago
parent
commit
5a2828c4df
14 changed files with 66 additions and 16 deletions
  1. +3
    -0
      README.md
  2. +1
    -1
      admin.js
  3. +1
    -0
      admin/admin.js
  4. +1
    -1
      admin/category/addCategory.js
  5. +1
    -1
      admin/downloads/manageDownloads.js
  6. +4
    -2
      admin/login/login.js
  7. +1
    -1
      admin/posts/newPost.js
  8. +0
    -0
      blogContent/posts/programming/everything-fibonacci.md
  9. +2
    -0
      includes/html/contact.html
  10. +5
    -0
      includes/html/header.html
  11. +1
    -1
      package.json
  12. +16
    -5
      posts/singlePost.js
  13. +26
    -0
      utils/markdownToHTML.js
  14. +4
    -4
      utils/sql.js

+ 3
- 0
README.md View File

@ -110,6 +110,9 @@ npm install memory-cache --save
npm install request
npm install nodemailer
npm install nodemailer-smtp-transport
npm install node-pandoc
```

+ 1
- 1
admin.js View File

@ -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(''));

+ 1
- 0
admin/admin.js View File

@ -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),

+ 1
- 1
admin/category/addCategory.js View File

@ -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)
{

+ 1
- 1
admin/downloads/manageDownloads.js View File

@ -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("<div class=\"col-md-6\">" + html.join('') + "</div>");
}).catch(function(error)

+ 4
- 2
admin/login/login.js View File

@ -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)
{

+ 1
- 1
admin/posts/newPost.js View File

@ -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)

blogContent/posts/programming/EverythingFibonacci.md → blogContent/posts/programming/everything-fibonacci.md View File


+ 2
- 0
includes/html/contact.html View File

@ -51,6 +51,8 @@
</div>
</form>
</div>
<br>
<br>
<script src='https://www.google.com/recaptcha/api.js'></script>

+ 5
- 0
includes/html/header.html View File

@ -25,6 +25,11 @@
}
p{font-size:18px;}
</style>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML-full" type="text/javascript"></script>
</head>
<body>

+ 1
- 1
package.json View File

@ -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",

+ 16
- 5
posts/singlePost.js View File

@ -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("<img").join("<img style=\"max-width: 100%;\" ");
html = html.split("<code>").join("<code class='hljs cpp'>");
html += "</div></div></div><br><br>";
html = html.split("<img").join("<img style=\"max-width: 100%;\" ");
html = html.split("<code>").join("<code class='hljs cpp'>");
html += "</div></div></div><br><br>";
resolve(htmlHead + html);
}).catch(function(error)
{
reject(error);
})
resolve(htmlHead + html);
});
}
catch(ex)

+ 26
- 0
utils/markdownToHTML.js View File

@ -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);
});
},
}

+ 4
- 4
utils/sql.js View File

@ -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)

Loading…
Cancel
Save