From 4bc957159dbf3db2481b6cd23ca32f81c8b1fadb Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sun, 8 Sep 2024 15:23:03 -0500 Subject: [PATCH] Move a couple of variables back out of the global space because that was bad. --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 92cf6f8e3..e10cb50d7 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -1,11 +1,7 @@ const _ = require('lodash'); const dedent = require('dedent-tabs').default; -const res = []; - -const pageMap = []; - -const walkPages = (iframeDocument)=>{ +const walkPages = (iframeDocument, pageMap)=>{ let current = 0; let skip = 0; let reset = 0; @@ -54,12 +50,15 @@ const recursiveAdd = (title, page, actualPage, targetDepth, child, curDepth=0)=> const getTOC = ()=>{ + const pageMap = []; + const res = []; + const iframe = document.getElementById('BrewRenderer'); const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6'); const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; - walkPages(iframeDocument); + walkPages(iframeDocument, pageMap); _.each(headings, (heading)=>{ const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, ''));