made non-blog content be removed by html class instead of by regex
All checks were successful
Web/pipeline/head This commit looks good

This commit is contained in:
Ell 2020-09-23 04:23:40 +02:00
parent 73cc32dc62
commit fb7c50f3e5
2 changed files with 115 additions and 111 deletions

View file

@ -83,7 +83,7 @@
<script src="scripts/cookieinfo.js"></script> <script src="scripts/cookieinfo.js"></script>
<div id="main"> <div id="main">
<!-- NOBLOG --> <div class="no-blog">
<!-- Home --> <!-- Home -->
<div class="jumbotron"> <div class="jumbotron">
<div class="container"> <div class="container">
@ -168,7 +168,7 @@
</div> </div>
<script src="scripts/blog.js"></script> <script src="scripts/blog.js"></script>
</div> </div>
<!-- /NOBLOG --> </div>
</div> </div>
</div> </div>
@ -182,7 +182,7 @@
</div> </div>
</div> </div>
<!-- NOBLOG --> <div class="no-blog">
<!-- Commissions --> <!-- Commissions -->
<div class="modal fade" id="commissions-modal" tabindex="-1"> <div class="modal fade" id="commissions-modal" tabindex="-1">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
@ -215,7 +215,7 @@
</div> </div>
</div> </div>
</div> </div>
<!-- /NOBLOG --> </div>
<!-- Impressum --> <!-- Impressum -->
<div class="modal fade" id="impressum-modal" tabindex="-1"> <div class="modal fade" id="impressum-modal" tabindex="-1">

View file

@ -7,23 +7,27 @@ const converter = require("./showdown")(2);
let folder = __dirname + "/../"; let folder = __dirname + "/../";
console.log("Refreshing blog sub-sites..."); console.log("Refreshing blog sub-sites...");
fs.readFile(folder + "index.html", function (_, data) { fs.readFile(folder + "index.html", function (_, html) {
// this can probably be done a lot easier but regex is hard ok let templateDom = new JSDOM(html);
var template = data.toString().replace(/<!-- ?NOBLOG ?-->([^](?!<!-- ?NOBLOG ?-->))*<!-- ?\/NOBLOG ?-->/g, ""); let noBlog = templateDom.window.document.getElementsByClassName("no-blog");
while (noBlog.length > 0)
noBlog[0].parentNode.removeChild(noBlog[0]);
let template = templateDom.serialize();
fs.readFile(folder + "blog/posts.json", function (_, data) { fs.readFile(folder + "blog/posts.json", function (_, data) {
let json = JSON.parse(data); let json = JSON.parse(data);
for (let i = 0; i < json.length; i++) { for (let i = 0; i < json.length; i++) {
let post = json[i]; let post = json[i];
fs.readFile(folder + "blog/" + post.id + ".md", function (_, content) { fs.readFile(folder + "blog/" + post.id + ".md", function (_, content) {
let dom = new JSDOM(template); let dom = new JSDOM(template);
var document = dom.window.document; let document = dom.window.document;
document.title += " - " + post.name; document.title += " - " + post.name;
document.querySelector('meta[property="og:title"]').setAttribute("content", post.name); document.querySelector('meta[property="og:title"]').setAttribute("content", post.name);
document.querySelector('meta[name="description"]').setAttribute("content", post.summary); document.querySelector('meta[name="description"]').setAttribute("content", post.summary);
document.querySelector('meta[property="og:description"]').setAttribute("content", post.summary); document.querySelector('meta[property="og:description"]').setAttribute("content", post.summary);
var nav = ""; let nav = "";
nav += '<a class="nav-item nav-link" href="/#blog">Back to Main Page</a>'; nav += '<a class="nav-item nav-link" href="/#blog">Back to Main Page</a>';
let last = getAdjacentPost(json, i, -1); let last = getAdjacentPost(json, i, -1);
if (last) if (last)
@ -33,7 +37,7 @@ fs.readFile(folder + "index.html", function (_, data) {
nav += '<a class="nav-item nav-link" href="/blog-' + next.id + '">Next Post</a>'; nav += '<a class="nav-item nav-link" href="/blog-' + next.id + '">Next Post</a>';
document.getElementById("nav-items").innerHTML = nav; document.getElementById("nav-items").innerHTML = nav;
var c = ""; let c = "";
c += '<div class="list-display rounded">'; c += '<div class="list-display rounded">';
c += '<div class="blog-isolated">' c += '<div class="blog-isolated">'
c += '<h1>' + post.name + '</h1>'; c += '<h1>' + post.name + '</h1>';
@ -48,8 +52,8 @@ fs.readFile(folder + "index.html", function (_, data) {
c += '</div></div>'; c += '</div></div>';
document.getElementById("main").innerHTML = c; document.getElementById("main").innerHTML = c;
let html = dom.serialize(); let ret = dom.serialize();
fs.writeFile(folder + "blog-" + post.id + ".html", html, function (_, _) {}); fs.writeFile(folder + "blog-" + post.id + ".html", ret, function (_, _) {});
}); });
} }
}); });