@mintlify/common 1.0.658 → 1.0.659
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DecoratedNavigationConfig } from '@mintlify/validation';
|
|
2
|
+
/**
|
|
3
|
+
* Generates a map from page paths to their hidden status based on navigation hierarchy.
|
|
4
|
+
* A page is hidden if:
|
|
5
|
+
* - It has noindex: true in its frontmatter, OR
|
|
6
|
+
* - Any parent group/division has hidden: true
|
|
7
|
+
* Assumes page hrefs in navWithPageContext have a leading / but config page paths do not.
|
|
8
|
+
* Outputted dictionary will NOT have a leading / in the dictionary keys.
|
|
9
|
+
*/
|
|
10
|
+
export declare function generatePathToHiddenDict(decoratedNav: DecoratedNavigationConfig): Map<string, boolean>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { divisions } from '@mintlify/validation';
|
|
2
|
+
import { isPage } from '../navigation/isPage.js';
|
|
3
|
+
import { optionallyRemoveLeadingSlash } from '../optionallyRemoveLeadingSlash.js';
|
|
4
|
+
/**
|
|
5
|
+
* Generates a map from page paths to their hidden status based on navigation hierarchy.
|
|
6
|
+
* A page is hidden if:
|
|
7
|
+
* - It has noindex: true in its frontmatter, OR
|
|
8
|
+
* - Any parent group/division has hidden: true
|
|
9
|
+
* Assumes page hrefs in navWithPageContext have a leading / but config page paths do not.
|
|
10
|
+
* Outputted dictionary will NOT have a leading / in the dictionary keys.
|
|
11
|
+
*/
|
|
12
|
+
export function generatePathToHiddenDict(decoratedNav) {
|
|
13
|
+
const pathToHiddenDict = new Map();
|
|
14
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, decoratedNav, false);
|
|
15
|
+
return pathToHiddenDict;
|
|
16
|
+
}
|
|
17
|
+
function generatePathToHiddenDictRecursive(pathToHiddenDict, nav, parentHidden) {
|
|
18
|
+
if (typeof nav !== 'object')
|
|
19
|
+
return;
|
|
20
|
+
// Determine the effective hidden status for this level (from group/tab hidden property)
|
|
21
|
+
const effectiveHidden = 'hidden' in nav && typeof nav.hidden === 'boolean' ? nav.hidden : parentHidden;
|
|
22
|
+
if (isPage(nav)) {
|
|
23
|
+
const key = optionallyRemoveLeadingSlash(nav.href);
|
|
24
|
+
// A page is hidden if parent has hidden: true OR page has noindex: true in frontmatter
|
|
25
|
+
const pageNoindex = 'noindex' in nav && nav.noindex === true;
|
|
26
|
+
const isHidden = effectiveHidden || pageNoindex;
|
|
27
|
+
// Only add hidden pages to the dictionary (more efficient)
|
|
28
|
+
// We keep the first value encountered to handle duplicate paths
|
|
29
|
+
if (isHidden && !pathToHiddenDict.has(key)) {
|
|
30
|
+
pathToHiddenDict.set(key, true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if ('pages' in nav) {
|
|
34
|
+
if ('root' in nav && typeof nav.root === 'object') {
|
|
35
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, nav.root, effectiveHidden);
|
|
36
|
+
}
|
|
37
|
+
for (const page of nav.pages) {
|
|
38
|
+
if (typeof page === 'object') {
|
|
39
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, page, effectiveHidden);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const key of ['groups', ...divisions]) {
|
|
44
|
+
if (key in nav) {
|
|
45
|
+
const items = nav[key];
|
|
46
|
+
if (Array.isArray(items)) {
|
|
47
|
+
for (const item of items) {
|
|
48
|
+
generatePathToHiddenDictRecursive(pathToHiddenDict, item, effectiveHidden);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/divisions/index.js
CHANGED