From d5958fa60aa1b4adcfa2ee367571adef34c485db Mon Sep 17 00:00:00 2001 From: Dario Ernst Date: Mon, 6 Dec 2021 09:53:02 +0100 Subject: [PATCH] Move columnizing script --- .gitignore | 1 + .../layouts/partials/printscript.html | 36 ------------------ themes/cookbook/static/js/print.js | 38 ++++++++++++++++++- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 5286d64..f01a4e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ public/ pdf/ +public/ diff --git a/themes/cookbook/layouts/partials/printscript.html b/themes/cookbook/layouts/partials/printscript.html index e87bf65..bb82e73 100644 --- a/themes/cookbook/layouts/partials/printscript.html +++ b/themes/cookbook/layouts/partials/printscript.html @@ -1,38 +1,2 @@ - diff --git a/themes/cookbook/static/js/print.js b/themes/cookbook/static/js/print.js index 1b9e5c3..b05e61a 100644 --- a/themes/cookbook/static/js/print.js +++ b/themes/cookbook/static/js/print.js @@ -29,4 +29,40 @@ if (hrs.length > 2) { } // Remove the footnote links -u(document.getElementsByClassName('footnote-backref')).remove() \ No newline at end of file +u(document.getElementsByClassName('footnote-backref')).remove() + +// Break ingredients into column-able blocks +window.addEventListener('load', function () { + const zutatenNode = document.evaluate('//*[@id="zutaten"]', document).iterateNext() + + let nodeBlocks = [[]] + let nextNode = zutatenNode.nextElementSibling + while (nextNode && nextNode.tagName != "H2") { + + if(nextNode.tagName == 'H4') { + nodeBlocks.push([]) + } + nodeBlocks[nodeBlocks.length - 1].push(nextNode) + + nextNode = nextNode.nextElementSibling + } + + let allIngredientsDiv = document.createElement('div') + allIngredientsDiv.id = "allZutaten" + allIngredientsDiv.classList.add('allZutaten') + let nodeBlockIndex = 0 + nodeBlocks.forEach(function(nodeArray) { + let outerDiv = document.createElement('div') + outerDiv.id = `wrap${nodeBlockIndex}` + + outerDiv.classList.add("zutatenWrapper") + allIngredientsDiv.appendChild(outerDiv) + for(elem of nodeArray) { + outerDiv.appendChild(elem) + } + + nodeBlockIndex += 1 + }) + zutatenNode.parentNode.insertBefore(allIngredientsDiv, zutatenNode.nextSibling) + console.log("Finished fiddling") +})