fixed book headings being reduced in blog posts
All checks were successful
Web/pipeline/head This commit looks good
All checks were successful
Web/pipeline/head This commit looks good
This commit is contained in:
parent
e8b22f684b
commit
9df7ecad8e
3 changed files with 10 additions and 8 deletions
|
@ -50,7 +50,7 @@ fs.readFile(`${folder}index.html`, function (_, html) {
|
||||||
let content;
|
let content;
|
||||||
if (post.book) {
|
if (post.book) {
|
||||||
document.head.innerHTML += /*html*/ `<link rel="stylesheet" href="../style/book.css">`;
|
document.head.innerHTML += /*html*/ `<link rel="stylesheet" href="../style/book.css">`;
|
||||||
content = util.extractBookData(file, post);
|
content = util.extractBookData(file, post, true);
|
||||||
} else {
|
} else {
|
||||||
content = converter.makeHtml(file.toString());
|
content = converter.makeHtml(file.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ function createFeed(callback) {
|
||||||
const index = i;
|
const index = i;
|
||||||
let extension = post.book ? "html" : "md";
|
let extension = post.book ? "html" : "md";
|
||||||
fs.readFile(`${__dirname}/../blog/src/${post.id}.${extension}`, function (_, file) {
|
fs.readFile(`${__dirname}/../blog/src/${post.id}.${extension}`, function (_, file) {
|
||||||
let content = post.book ? util.extractBookData(file, post) : converter.makeHtml(file.toString());
|
let content = post.book ? util.extractBookData(file, post, false) : converter.makeHtml(file.toString());
|
||||||
feed.addItem({
|
feed.addItem({
|
||||||
title: `${post.name}${post.archived ? " (Archived)" : ""}`,
|
title: `${post.name}${post.archived ? " (Archived)" : ""}`,
|
||||||
link: `https://ellpeck.de/blog/${post.id}`,
|
link: `https://ellpeck.de/blog/${post.id}`,
|
||||||
|
|
14
node/util.js
14
node/util.js
|
@ -13,18 +13,20 @@ exports.showdown = function (headerLevel) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.extractBookData = function (file, post) {
|
exports.extractBookData = function (file, post, reduceHeadings) {
|
||||||
let html = new JSDOM(file);
|
let html = new JSDOM(file);
|
||||||
let page = html.window.document.getElementById("page");
|
let page = html.window.document.getElementById("page");
|
||||||
// remove header section
|
// remove header section
|
||||||
let header = page.getElementsByTagName("header");
|
let header = page.getElementsByTagName("header");
|
||||||
while (header.length > 0)
|
while (header.length > 0)
|
||||||
header[0].parentNode.removeChild(header[0]);
|
header[0].parentNode.removeChild(header[0]);
|
||||||
// reduce all headings by 1
|
if (reduceHeadings) {
|
||||||
for (let h = 5; h >= 1; h--) {
|
// reduce all headings by 1
|
||||||
let heading = page.getElementsByTagName(`h${h}`);
|
for (let h = 5; h >= 1; h--) {
|
||||||
while (heading.length > 0)
|
let heading = page.getElementsByTagName(`h${h}`);
|
||||||
this.changeTag(heading[0], `h${h+1}`);
|
while (heading.length > 0)
|
||||||
|
this.changeTag(heading[0], `h${h+1}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return /*html*/ `
|
return /*html*/ `
|
||||||
|
|
Loading…
Reference in a new issue