mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 18:32:40 +00:00
Merge branch 'actualPageNumber' of github.com:dbolack-ab/homebrewery into actualPageNumber
This commit is contained in:
@@ -1,26 +1,23 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
const walkPages = (iframeDocument, pageMap)=>{
|
const mapPages = (iframeDocument, pageMap)=>{
|
||||||
let current = 0;
|
let actualPage = 0;
|
||||||
let skip = 0;
|
let mappedPage = 0;
|
||||||
let reset = 0;
|
|
||||||
const pages = iframeDocument.querySelectorAll('.page');
|
const pages = iframeDocument.querySelectorAll('.page');
|
||||||
_.each(pages, (page)=>{
|
_.each(pages, (page)=>{
|
||||||
let showPage = true;
|
actualPage++;
|
||||||
current++;
|
const doSkip = page.querySelector('.skipCounting');
|
||||||
const doSkip = (page.querySelector('.skipCounting'));
|
const doReset = page.querySelector('.resetCounting');
|
||||||
const doReset = (page.querySelector('.resetCounting'));
|
|
||||||
if(doReset) {
|
if(doReset)
|
||||||
reset = current - 1;
|
mappedPage = 1;
|
||||||
skip = 0;
|
if(!doSkip && !doReset)
|
||||||
} else if(doSkip){
|
mappedPage++;
|
||||||
skip += 1;
|
|
||||||
showPage = false;
|
pageMap[actualPage] = {
|
||||||
}
|
mappedPage : mappedPage,
|
||||||
pageMap[current] = {
|
showPage : !doSkip
|
||||||
pageNumber : current - reset - skip,
|
|
||||||
showPage : showPage
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -51,24 +48,24 @@ const recursiveAdd = (title, page, actualPage, targetDepth, child, curDepth=0)=>
|
|||||||
|
|
||||||
const getTOC = ()=>{
|
const getTOC = ()=>{
|
||||||
const pageMap = [];
|
const pageMap = [];
|
||||||
const res = [];
|
const entries = [];
|
||||||
|
|
||||||
const iframe = document.getElementById('BrewRenderer');
|
const iframe = document.getElementById('BrewRenderer');
|
||||||
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
||||||
const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||||
const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
|
const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
|
||||||
|
|
||||||
walkPages(iframeDocument, pageMap);
|
mapPages(iframeDocument, pageMap);
|
||||||
|
|
||||||
_.each(headings, (heading)=>{
|
_.each(headings, (heading)=>{
|
||||||
const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, ''));
|
const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, ''));
|
||||||
const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC');
|
const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC');
|
||||||
|
|
||||||
if(ToCExclude != 'exclude') {
|
if(ToCExclude != 'exclude') {
|
||||||
recursiveAdd(heading.textContent.trim(), pageMap[onPage], onPage, headerDepth.indexOf(heading.tagName), res);
|
recursiveAdd(heading.textContent.trim(), pageMap[onPage], onPage, headerDepth.indexOf(heading.tagName), entries);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +73,7 @@ const ToCIterate = (entries, curDepth=0)=>{
|
|||||||
const levelPad = ['- ###', ' - ####', ' - ', ' - ', ' - ', ' - '];
|
const levelPad = ['- ###', ' - ####', ' - ', ' - ', ' - ', ' - '];
|
||||||
const toc = [];
|
const toc = [];
|
||||||
if(entries.title !== null){
|
if(entries.title !== null){
|
||||||
if(entries.page.showPage) toc.push(`${levelPad[curDepth]} [{{ ${entries.title}}}{{ ${entries.page.pageNumber}}}](#${entries.anchor})`);
|
if(entries.page.showPage) toc.push(`${levelPad[curDepth]} [{{ ${entries.title}}}{{ ${entries.page.mappedPage}}}](#${entries.anchor})`);
|
||||||
}
|
}
|
||||||
if(entries.children.length) {
|
if(entries.children.length) {
|
||||||
_.each(entries.children, (entry, idx)=>{
|
_.each(entries.children, (entry, idx)=>{
|
||||||
|
|||||||
Reference in New Issue
Block a user