mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-01 02:02:43 +00:00
Small logic cleanup and renaming
This commit is contained in:
@@ -5,26 +5,23 @@ const res = [];
|
|||||||
|
|
||||||
const pageMap = [];
|
const pageMap = [];
|
||||||
|
|
||||||
const walkPages = (iframeDocument)=>{
|
const mapPages = (iframeDocument)=>{
|
||||||
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
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -59,7 +56,7 @@ const getTOC = ()=>{
|
|||||||
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);
|
mapPages(iframeDocument);
|
||||||
|
|
||||||
_.each(headings, (heading)=>{
|
_.each(headings, (heading)=>{
|
||||||
const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, ''));
|
const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, ''));
|
||||||
@@ -77,7 +74,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