some code style improvements
Web/pipeline/head This commit looks good Details

This commit is contained in:
Ell 2021-03-19 12:02:31 +01:00
parent 40246ef683
commit 8a14c03989
4 changed files with 22 additions and 19 deletions

View File

@ -1,18 +1,18 @@
const replacements = new Map();
replacements.set(/<imp>([^<]*)<r>/g, function (content) {
return `<span class="imp">${content}</span>`
return `<span class="imp">${content}</span>`;
});
replacements.set(/<item>([^<]*)<r>/g, function (content) {
return `<span class="item">${content}</span>`
return `<span class="item">${content}</span>`;
});
replacements.set(/<n>/g, function (_content) {
return "<br>"
return "<br>";
});
replacements.set(/<i>([^<]*)<r>/g, function (content) {
return `<em>${content}</em>`
return `<em>${content}</em>`;
});
replacements.set(/<tifisgrin>([^<]*)<r>/g, function (content) {
return `<span class="tifisgrin">${content}</span>`
return `<span class="tifisgrin">${content}</span>`;
});
$.ajax({
@ -47,7 +47,7 @@ function populateManual(lang) {
}
sidebar.append("<hr>");
sidebar.append(`<a href="https://ellpeck.de">Main Site</a>`)
sidebar.append(`<a href="https://ellpeck.de">Main Site</a>`);
sidebar.append(`<a href="https://ellpeck.de/impressum">Impressum</a>`);
sidebar.append(`<a href="https://ellpeck.de/privacy">Privacy</a>`);
sidebar.append(`<a href="https://git.ellpeck.de/Ellpeck/Web">&copy; Ellpeck</a>`);
@ -58,8 +58,9 @@ function populateManual(lang) {
function replaceFormatting(text) {
for (let [k, v] of replacements.entries()) {
const finalV = v;
text = text.replace(k, function (_substring, group) {
return v(group);
return finalV(group);
});
}
return text;

View File

@ -4,7 +4,7 @@ const {
const fs = require("fs");
const converter = require("./showdown")(2);
let folder = `${__dirname}/../`;
const folder = `${__dirname}/../`;
console.log("Refreshing blog sub-sites...");
fs.readFile(`${folder}index.html`, function (_, html) {
@ -22,12 +22,15 @@ fs.readFile(`${folder}index.html`, function (_, html) {
if (element.href && element.href.startsWith("./"))
element.href = `../${element.href.substring(2)}`;
}
let template = templateDom.serialize();
const template = templateDom.serialize();
fs.readFile(`${folder}blog/src/posts.json`, function (_, data) {
let json = JSON.parse(data.toString());
const json = JSON.parse(data.toString());
for (let i = 0; i < json.length; i++) {
let post = json[i];
const post = json[i];
const index = i;
const last = getAdjacentPost(json, index, -1);
const next = getAdjacentPost(json, index, 1);
fs.readFile(`${folder}blog/src/${post.id}.md`, function (_, content) {
let dom = new JSDOM(template);
let document = dom.window.document;
@ -37,8 +40,6 @@ fs.readFile(`${folder}index.html`, function (_, html) {
document.querySelector('meta[name="description"]').setAttribute("content", post.summary);
document.querySelector('meta[property="og:description"]').setAttribute("content", post.summary);
let last = getAdjacentPost(json, i, -1);
let next = getAdjacentPost(json, i, 1);
document.getElementById("nav-items").innerHTML = /*html*/ `
<a class="nav-item nav-link" href="/#blog">Back to Main Page</a>
${last ? /*html*/ `<a class="nav-item nav-link" href="/blog/${last.id}">Previous ${post.cat} Post</a>` : ""}

View File

@ -33,12 +33,13 @@ function createFeed(callback) {
}
});
const finalCallback = callback;
fs.readFile(`${__dirname}/../blog/src/posts.json`, function (_, data) {
let json = JSON.parse(data);
for (let i = json.length - 1; i >= 0; i--) {
let post = json[i];
let date = new Date(post.date);
const post = json[i];
const date = new Date(post.date);
const index = i;
fs.readFile(`${__dirname}/../blog/src/${post.id}.md`, function (_, content) {
let html = converter.makeHtml(content.toString());
feed.addItem({
@ -55,8 +56,8 @@ function createFeed(callback) {
if (feed.categories.indexOf(post.cat) < 0)
feed.addCategory(post.cat);
if (i === 0)
callback(feed);
if (index === 0)
finalCallback(feed);
});
}
});

View File

@ -7,4 +7,4 @@ module.exports = function (headerLevel) {
headerLevelStart: headerLevel,
extensions: ["prettify", "footnotes"]
});
}
};