mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-09 09:22:38 +00:00
Address requested changes
This commit is contained in:
@@ -11,18 +11,31 @@ const HeaderNav = React.forwardRef(({}, pagesRef)=>{
|
|||||||
const renderHeaderLinks = ()=>{
|
const renderHeaderLinks = ()=>{
|
||||||
if(!pagesRef.current) return;
|
if(!pagesRef.current) return;
|
||||||
|
|
||||||
const excludedPages = {
|
// Top Level Pages
|
||||||
'.frontCover' : 'Cover Page',
|
// Pages that contain an element with a specified class will NOT have its content scanned for navigation headers
|
||||||
'.toc' : 'Contents'
|
// e.g. cover pages, table of content pages
|
||||||
|
// Instead, a label will be added to the navigation at the page level
|
||||||
|
// ---
|
||||||
|
// The property name is class that will be used for detecting the page is a top level page
|
||||||
|
// The property value is a function that returns the text to be used
|
||||||
|
|
||||||
|
const topLevelPages = {
|
||||||
|
'.frontCover' : (text)=>{ return text ? `Cover: ${text}` : 'Cover Page'; },
|
||||||
|
'.insideCover' : (text)=>{ return text ? `Interior: ${text}` : 'Interior Cover Page'; },
|
||||||
|
'.partCover' : (text)=>{ return text ? `Section: ${text}` : 'Section Cover Page'; },
|
||||||
|
'.backCover' : (text)=>{ return text ? `Back: ${text}` : 'Rear Cover Page'; },
|
||||||
|
'.toc' : ()=>{ return 'Table of Contents'; },
|
||||||
};
|
};
|
||||||
|
|
||||||
const excluded = Object.keys(excludedPages).join(',');
|
const getTextContent = (el, pageType)=>{ return el.querySelector(pageType).textContent; };
|
||||||
|
|
||||||
|
const topLevelPageSelector = Object.keys(topLevelPages).join(',');
|
||||||
|
|
||||||
const selector = [
|
const selector = [
|
||||||
'.pages > .page', // All page elements, which by definition have IDs
|
'.pages > .page', // All page elements, which by definition have IDs
|
||||||
`.page:not(:has(${excluded})) > [id]`, // All direct children of non-excluded .pages with an ID (Legacy)
|
`.page:not(:has(${topLevelPageSelector})) > [id]`, // All direct children of non-excluded .pages with an ID (Legacy)
|
||||||
`.page:not(:has(${excluded})) > .columnWrapper > [id]`, // All direct children of non-excluded .page > .columnWrapper with an ID (V3)
|
`.page:not(:has(${topLevelPageSelector})) > .columnWrapper > [id]`, // All direct children of non-excluded .page > .columnWrapper with an ID (V3)
|
||||||
`.page:not(:has(${excluded})) h2`, // All non-excluded H2 titles, like Monster frame titles
|
`.page:not(:has(${topLevelPageSelector})) h2`, // All non-excluded H2 titles, like Monster frame titles
|
||||||
];
|
];
|
||||||
const elements = pagesRef.current.querySelectorAll(selector.join(','));
|
const elements = pagesRef.current.querySelectorAll(selector.join(','));
|
||||||
if(!elements) return;
|
if(!elements) return;
|
||||||
@@ -39,9 +52,9 @@ const HeaderNav = React.forwardRef(({}, pagesRef)=>{
|
|||||||
elements.forEach((el)=>{
|
elements.forEach((el)=>{
|
||||||
if(el.className.match(/\bpage\b/)) {
|
if(el.className.match(/\bpage\b/)) {
|
||||||
let text = `Page ${el.id.slice(1)}`; // The ID of a page *should* always be equal to `p` followed by the page number
|
let text = `Page ${el.id.slice(1)}`; // The ID of a page *should* always be equal to `p` followed by the page number
|
||||||
Object.keys(excludedPages).every((pageType)=>{
|
Object.keys(topLevelPages).every((pageType)=>{
|
||||||
if(el.querySelector(pageType)){ // If the page contains a table of contents, add "- Contents" to the display text
|
if(el.querySelector(pageType)){ // If a Top Level Page, add the text result to the navigation text
|
||||||
text += ` - ${excludedPages[pageType]}`;
|
text += ` - ${topLevelPages[pageType](getTextContent(el, pageType))}`;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user