Web/node/util.js
Ell a33d718416
All checks were successful
Web/pipeline/head This commit looks good
extract some stuff to utility class
2021-03-31 19:56:33 +02:00

31 lines
1.2 KiB
JavaScript

const {
JSDOM
} = require("jsdom");
const showdown = require("showdown");
require("./lib/showdown-prettify");
require("./lib/showdown-footnotes");
module.exports = {
extractBookData: function (file, post) {
let html = new JSDOM(file);
let page = html.window.document.getElementById("page");
let header = page.getElementsByTagName("header");
while (header.length > 0)
header[0].parentNode.removeChild(header[0]);
return /*html*/ `
${post.prompt ? /*html*/ `<p class="meta-info"><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>` : ""}
${page.outerHTML}
`;
},
replaceRelativeLinks: function (element, tag) {
if (element[tag] && element[tag].startsWith("./"))
element[tag] = `../${element[tag].substring(2)}`;
},
showdown: function (headerLevel) {
return new showdown.Converter({
parseImgDimensions: true,
headerLevelStart: headerLevel,
extensions: ["prettify", "footnotes"]
});
}
};