Browse Source

fixed book headings being reduced in blog posts

master
Ellpeck 4 months ago
parent
commit
9df7ecad8e
  1. 2
      node/blog.js
  2. 2
      node/rss.js
  3. 14
      node/util.js

2
node/blog.js

@ -50,7 +50,7 @@ fs.readFile(`${folder}index.html`, function (_, html) {
let content;
if (post.book) {
document.head.innerHTML += /*html*/ `<link rel="stylesheet" href="../style/book.css">`;
content = util.extractBookData(file, post);
content = util.extractBookData(file, post, true);
} else {
content = converter.makeHtml(file.toString());
}

2
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}`,

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 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*/ `

Loading…
Cancel
Save