fixed book headings being reduced in blog posts
All checks were successful
Web/pipeline/head This commit looks good

This commit is contained in:
Ell 2021-04-06 19:29:04 +02:00
parent e8b22f684b
commit 9df7ecad8e
3 changed files with 10 additions and 8 deletions

View file

@ -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());
} }

View file

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

View file

@ -13,19 +13,21 @@ 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]);
if (reduceHeadings) {
// reduce all headings by 1 // reduce all headings by 1
for (let h = 5; h >= 1; h--) { for (let h = 5; h >= 1; h--) {
let heading = page.getElementsByTagName(`h${h}`); let heading = page.getElementsByTagName(`h${h}`);
while (heading.length > 0) while (heading.length > 0)
this.changeTag(heading[0], `h${h+1}`); this.changeTag(heading[0], `h${h+1}`);
} }
}
return /*html*/ ` return /*html*/ `
${post.prompt ? /*html*/ `<p><i>This story was inspired by a Reedsy Prompt and submitted to their competition. As such, it has also been published on <a href="${post.prompt}">their website</a>.</i></p>` : ""} ${post.prompt ? /*html*/ `<p><i>This story was inspired by a Reedsy Prompt and submitted to their competition. As such, it has also been published on <a href="${post.prompt}">their website</a>.</i></p>` : ""}