Skip to content

Commit

Permalink
moving some reporting out of index
Browse files Browse the repository at this point in the history
  • Loading branch information
stevector committed Dec 18, 2024
1 parent b2ad919 commit 3575f16
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
35 changes: 7 additions & 28 deletions src/components/omniSidebarNav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import {
turnItemsIntoLinks,
} from './helpers.js';

// @todo, remove the reporting before merging this PR.
import allWrittenPaths from './all-written-paths.js';

/* Reporting debugging code.
import {
flattenOmniItems,
CalculateFilteredPathsInMenu,
eliminateExceptions,
filteredWrittenPaths
} from './reporting';
*/

import './style.css';

// @todo, run prettier one more time on this directory before removing it from the PR.

const OmniSidebarNav = ({
activePage,
fallbackItems = null,
Expand All @@ -28,34 +27,14 @@ const OmniSidebarNav = ({
}) => {
const OmniItems = getOmniItems();

const exceptions = [
'https://certification.pantheon.io/',
'/404.html',
'/404/',
];
const RegExExceptions = [
// a regular expression that matches all paths that contain the '/contributors/' with the preceding and following slashes as well as more characters after the slash
/.*\/contributors\/.*/,
/.*\/release-notes\/.*/,
/.*\/iframeembeds\/.*/,
/.*\/search\/.*/,
/.*\/terminus\/commands\/.*/,
];

const filteredWrittenPaths = eliminateExceptions(
allWrittenPaths,
exceptions,
RegExExceptions,
);
/* Reporting debug code
const flattenedOmniItems = flattenOmniItems(OmniItems);
const results = CalculateFilteredPathsInMenu(
filteredWrittenPaths,
flattenedOmniItems,
);

// const results = calculateNumberOfPathsInMenu(allWrittenPaths, OmniItems, exceptions);

);
console.log(results);
*/

const menuItems = getOmniSidebarActiveSection(activePage, OmniItems);

Expand Down
46 changes: 26 additions & 20 deletions src/components/omniSidebarNav/reporting.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import allWrittenPaths from './all-written-paths.js';

const flattenOmniItems = (menuItems) => {
// loop over the omniItems and make a flattened array of all the links
// this function should be recursive.
Expand All @@ -13,26 +15,6 @@ const flattenOmniItems = (menuItems) => {
return [...new Set(flattened)];
};

const InWrittenPathOrExceptions = (
linkPath,
flattened = [],
allowedExceptions = [],
) => {
// check any of the exceptions are present in the linkPath
// if they are, return true
for (let exception of allowedExceptions) {
if (linkPath.includes(exception)) {
return true;
}
}

if (flattened.includes(linkPath)) {
return true;
} else {
return false;
}
};

const InMenuOrExceptions = (
linkPath,
flattened = [],
Expand Down Expand Up @@ -97,9 +79,33 @@ const CalculateFilteredPathsInMenu = (
};
};

const RegExExceptions = [
// a regular expression that matches all paths that contain the '/contributors/' with the preceding and following slashes as well as more characters after the slash
/.*\/contributors\/.*/,
/.*\/release-notes\/.*/,
/.*\/iframeembeds\/.*/,
/.*\/search\/.*/,
/.*\/terminus\/commands\/.*/,
];

const exceptions = [
'https://certification.pantheon.io/',
'/404.html',
'/404/',
];

const filteredWrittenPaths = eliminateExceptions(
allWrittenPaths,
exceptions,
RegExExceptions,
);


export {
flattenOmniItems,
InMenuOrExceptions,
eliminateExceptions,
CalculateFilteredPathsInMenu,

filteredWrittenPaths
};

0 comments on commit 3575f16

Please sign in to comment.