From 9df7ecad8e52e55b4417701b6db08d13e04cf0e6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 6 Apr 2021 19:29:04 +0200 Subject: [PATCH] fixed book headings being reduced in blog posts --- node/blog.js | 2 +- node/rss.js | 2 +- node/util.js | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/node/blog.js b/node/blog.js index 099a3e9..7fa77ef 100644 --- a/node/blog.js +++ b/node/blog.js @@ -50,7 +50,7 @@ fs.readFile(`${folder}index.html`, function (_, html) { let content; if (post.book) { document.head.innerHTML += /*html*/ ``; - content = util.extractBookData(file, post); + content = util.extractBookData(file, post, true); } else { content = converter.makeHtml(file.toString()); } diff --git a/node/rss.js b/node/rss.js index d6e9efc..b61b5db 100644 --- a/node/rss.js +++ b/node/rss.js @@ -43,7 +43,7 @@ function createFeed(callback) { const index = i; let extension = post.book ? "html" : "md"; 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({ title: `${post.name}${post.archived ? " (Archived)" : ""}`, link: `https://ellpeck.de/blog/${post.id}`, diff --git a/node/util.js b/node/util.js index 1def6a4..3ed0b15 100644 --- a/node/util.js +++ b/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 page = html.window.document.getElementById("page"); // remove header section let header = page.getElementsByTagName("header"); while (header.length > 0) header[0].parentNode.removeChild(header[0]); - // reduce all headings by 1 - for (let h = 5; h >= 1; h--) { - let heading = page.getElementsByTagName(`h${h}`); - while (heading.length > 0) - this.changeTag(heading[0], `h${h+1}`); + if (reduceHeadings) { + // reduce all headings by 1 + for (let h = 5; h >= 1; h--) { + let heading = page.getElementsByTagName(`h${h}`); + while (heading.length > 0) + this.changeTag(heading[0], `h${h+1}`); + } } return /*html*/ `