@mintlify/validation
Advanced tools
Comparing version 0.1.266 to 0.1.267
@@ -58,2 +58,1 @@ import { zodToJsonSchema } from 'zod-to-json-schema'; | ||
export * from './mint-config/schemas/v2/properties/index.js'; | ||
export * from './types/index.js'; |
@@ -26,2 +26,1 @@ import { DocsConfig } from './mint-config/schemas/v2/index.js'; | ||
export * from './mint-config/schemas/v2/properties/index.js'; | ||
export * from './types/index.js'; |
@@ -58,2 +58,1 @@ import { zodToJsonSchema } from 'zod-to-json-schema'; | ||
export * from './mint-config/schemas/v2/properties/index.js'; | ||
export * from './types/index.js'; |
@@ -13,2 +13,1 @@ import { z } from 'zod'; | ||
}>; | ||
export type Color = z.infer<typeof colorSchemaWithOptionalLightAndDark>; |
@@ -5,2 +5,1 @@ export * from './divisions.js'; | ||
export * from './openapi.js'; | ||
export * from './color.js'; |
@@ -5,2 +5,1 @@ export * from './divisions.js'; | ||
export * from './openapi.js'; | ||
export * from './color.js'; |
import { MintConfigType } from '@mintlify/models'; | ||
import { NavigationConfig } from '../schemas/v2/properties/navigation/index.js'; | ||
/** | ||
* Priority | ||
* 1. versions (including locales) | ||
* 2. anchors (global anchors) | ||
* 3. tabs (tabs) | ||
* 4. groups | ||
*/ | ||
export declare const updateNavigationToDocsConfig: (config: MintConfigType) => NavigationConfig; |
@@ -1,2 +0,1 @@ | ||
import isAbsoluteUrl from 'is-absolute-url'; | ||
import _ from 'lodash'; | ||
@@ -56,4 +55,4 @@ const DEFAULT_TAB = { | ||
if (typeof page === 'string') { | ||
if ((!prefix || ensureLeadingSlash(page).startsWith(ensureLeadingSlash(prefix))) && | ||
!ignoredDivisions.some((d) => ensureLeadingSlash(page).startsWith(ensureLeadingSlash(d.url)))) { | ||
if ((!prefix || page.startsWith(prefix)) && | ||
!ignoredDivisions.some((d) => page.startsWith(d.url))) { | ||
groupPages.push(page); | ||
@@ -83,3 +82,4 @@ } | ||
}; | ||
const processDivisions = (type, divisions = [], navigationGroups = [], shouldInsertRemainingGroups = false, versionName, config, otherDivisions) => { | ||
const processDivisions = (type, divisions = [], navigationGroups = [], shouldInsertRemainingGroups = false, versionName, config) => { | ||
var _a, _b; | ||
let remainingGroups = filterGroupsByVersion(navigationGroups, versionName); | ||
@@ -105,31 +105,8 @@ const result = divisions | ||
} | ||
const ignoredDivisions = divisions.filter((d) => ensureLeadingSlash(d.url).startsWith(ensureLeadingSlash(division.url)) && | ||
d.url !== division.url); | ||
let moreTabs = []; | ||
let moreAnchors = []; | ||
// process the other divisions | ||
if (otherDivisions === null || otherDivisions === void 0 ? void 0 : otherDivisions.length) { | ||
const matchedDivisions = otherDivisions.filter((d) => { | ||
return ensureLeadingSlash(d.url).startsWith(ensureLeadingSlash(division.url)); | ||
}); | ||
if (matchedDivisions.length) { | ||
const { tabs, anchors } = processDivisions(type === 'tabs' ? 'anchors' : 'tabs', matchedDivisions, navigationGroups, false, versionName, config); | ||
moreTabs = tabs; | ||
moreAnchors = anchors; | ||
} | ||
} | ||
const ignoredDivisions = divisions.filter((d) => d.url.startsWith(division.url) && d.url !== division.url); | ||
const { matchedGroups, unmatchedGroups } = findPagesForPrefix(remainingGroups, division, versionName, ignoredDivisions); | ||
remainingGroups = unmatchedGroups; | ||
if (matchedGroups.length) { | ||
if (matchedGroups.length) { | ||
const divisionWithoutHref = _.omit(baseDivision, 'href'); | ||
if (moreTabs.length) | ||
return Object.assign(Object.assign({}, divisionWithoutHref), { tabs: moreTabs }); | ||
if (moreAnchors.length) | ||
return Object.assign(Object.assign({}, divisionWithoutHref), { anchors: moreAnchors }); | ||
return Object.assign(Object.assign({}, divisionWithoutHref), { groups: matchedGroups }); | ||
} | ||
return Object.assign(Object.assign({}, _.omit(baseDivision, 'href')), { groups: matchedGroups }); | ||
} | ||
if (!matchedGroups.length && !isAbsoluteUrl(division.url)) | ||
return undefined; | ||
return baseDivision; | ||
@@ -140,3 +117,11 @@ }) | ||
const { matchedGroups } = findPagesForPrefix(remainingGroups, undefined, versionName, []); | ||
result.unshift(Object.assign(Object.assign({}, getPrimaryConfig(type === 'tabs' ? 'tab' : 'anchor', config)), { groups: matchedGroups })); | ||
if (type === 'tabs') { | ||
result.unshift(Object.assign(Object.assign({}, (((_a = config === null || config === void 0 ? void 0 : config.primaryTab) === null || _a === void 0 ? void 0 : _a.name) | ||
? Object.assign({ tab: config.primaryTab.name }, (config.primaryTab.isDefaultHidden !== undefined && { | ||
hidden: config.primaryTab.isDefaultHidden, | ||
})) : DEFAULT_TAB)), { groups: matchedGroups })); | ||
} | ||
else { | ||
result.push(Object.assign(Object.assign({}, (((_b = config === null || config === void 0 ? void 0 : config.topAnchor) === null || _b === void 0 ? void 0 : _b.name) ? { anchor: config.topAnchor.name } : DEFAULT_ANCHOR)), { groups: matchedGroups })); | ||
} | ||
} | ||
@@ -184,8 +169,5 @@ if (type === 'tabs') { | ||
const versionName = typeof version === 'string' ? version : version.name; | ||
const versionHref = typeof version === 'string' ? undefined : version.url; | ||
const baseVersion = { | ||
version: versionName, | ||
}; | ||
if (versionHref) | ||
return Object.assign(Object.assign({}, baseVersion), { href: versionHref }); | ||
const { matchedGroups } = findPagesForVersionOrLanguage(navigationGroups, versionName, prefixes); | ||
@@ -200,54 +182,33 @@ return Object.assign(Object.assign({}, baseVersion), { groups: matchedGroups }); | ||
}; | ||
/** | ||
* Priority | ||
* 1. versions (including locales) | ||
* 2. anchors (global anchors) | ||
* 3. tabs (tabs) | ||
* 4. groups | ||
*/ | ||
export const updateNavigationToDocsConfig = (config) => { | ||
let { tabs, anchors, versions } = config; | ||
const groups = config.navigation; | ||
const { navigation: groups, tabs, anchors, versions } = config; | ||
const { tabs: globalTabs, anchors: globalAnchors, versions: globalVersions, } = getGlobalDivisions(config); | ||
const hasTabs = tabs === null || tabs === void 0 ? void 0 : tabs.length; | ||
const hasAnchors = anchors === null || anchors === void 0 ? void 0 : anchors.length; | ||
tabs = (globalTabs === null || globalTabs === void 0 ? void 0 : globalTabs.length) ? [] : tabs; | ||
anchors = (globalAnchors === null || globalAnchors === void 0 ? void 0 : globalAnchors.length) ? [] : anchors; | ||
versions = (globalVersions === null || globalVersions === void 0 ? void 0 : globalVersions.length) ? [] : versions; | ||
// process divisions | ||
const getUpdatedNavigation = (groups, config, versionName) => { | ||
const topLevelDivision = findMostInclusiveDivision(tabs, anchors); | ||
if (topLevelDivision === 'anchors') { | ||
if (hasAnchors) { | ||
const { anchors: anchorsResult, remainingGroups } = processDivisions('anchors', anchors, groups, false, versionName, config, tabs); | ||
if (remainingGroups.length || (tabs === null || tabs === void 0 ? void 0 : tabs.length)) { | ||
if (tabs === null || tabs === void 0 ? void 0 : tabs.length) { | ||
const { tabs: tabsResult } = processDivisions('tabs', tabs, remainingGroups.length ? remainingGroups : groups, true, versionName, config); | ||
anchorsResult.unshift(Object.assign(Object.assign({}, getPrimaryConfig('anchor', config)), { tabs: tabsResult })); | ||
} | ||
else { | ||
const { matchedGroups } = findPagesForPrefix(remainingGroups, undefined, versionName); | ||
anchorsResult.unshift(Object.assign(Object.assign({}, getPrimaryConfig('anchor', config)), { groups: matchedGroups })); | ||
} | ||
const getUpdatedNavigation = (groups, tabs, anchors, versionName, config) => { | ||
var _a, _b; | ||
if ((anchors === null || anchors === void 0 ? void 0 : anchors.length) && !(globalAnchors === null || globalAnchors === void 0 ? void 0 : globalAnchors.length)) { | ||
const { anchors: anchorsResult, remainingGroups } = processDivisions('anchors', anchors, groups, false, versionName, config); | ||
if (remainingGroups.length || (tabs === null || tabs === void 0 ? void 0 : tabs.length)) { | ||
if ((tabs === null || tabs === void 0 ? void 0 : tabs.length) && !(globalTabs === null || globalTabs === void 0 ? void 0 : globalTabs.length)) { | ||
const { tabs: tabsResult } = processDivisions('tabs', tabs, remainingGroups.length ? remainingGroups : groups, true, versionName, config); | ||
anchorsResult.push(Object.assign(Object.assign({}, (((_a = config === null || config === void 0 ? void 0 : config.topAnchor) === null || _a === void 0 ? void 0 : _a.name) ? { anchor: config.topAnchor.name } : DEFAULT_ANCHOR)), { tabs: tabsResult })); | ||
} | ||
return { anchors: anchorsResult }; | ||
} | ||
if (hasTabs) { | ||
const { tabs: tabsResult } = processDivisions('tabs', tabs, groups, true, versionName, config); | ||
return { tabs: tabsResult }; | ||
} | ||
} | ||
else { | ||
if (hasTabs) { | ||
const { tabs: tabsResult, remainingGroups } = processDivisions('tabs', tabs, groups, false, versionName, config, anchors); | ||
if (remainingGroups.length || (anchors === null || anchors === void 0 ? void 0 : anchors.length)) { | ||
if (anchors === null || anchors === void 0 ? void 0 : anchors.length) { | ||
const { anchors: anchorsResult } = processDivisions('anchors', anchors, remainingGroups.length ? remainingGroups : groups, true, versionName, config); | ||
tabsResult.unshift(Object.assign(Object.assign({}, getPrimaryConfig('tab', config)), { anchors: anchorsResult })); | ||
} | ||
else { | ||
const { matchedGroups } = findPagesForPrefix(remainingGroups, undefined, versionName); | ||
tabsResult.unshift(Object.assign(Object.assign({}, getPrimaryConfig('tab', config)), { groups: matchedGroups })); | ||
} | ||
else { | ||
const { matchedGroups } = findPagesForPrefix(remainingGroups, undefined, versionName); | ||
anchorsResult.push(Object.assign(Object.assign({}, (((_b = config === null || config === void 0 ? void 0 : config.topAnchor) === null || _b === void 0 ? void 0 : _b.name) ? { anchor: config.topAnchor.name } : DEFAULT_ANCHOR)), { groups: matchedGroups })); | ||
} | ||
return { tabs: tabsResult }; | ||
} | ||
if (hasAnchors) { | ||
const { anchors: anchorsResult } = processDivisions('anchors', anchors, groups, true, versionName, config); | ||
return { anchors: anchorsResult }; | ||
} | ||
return { anchors: anchorsResult }; | ||
} | ||
if ((tabs === null || tabs === void 0 ? void 0 : tabs.length) && !(globalTabs === null || globalTabs === void 0 ? void 0 : globalTabs.length)) { | ||
const { tabs: tabsResult } = processDivisions('tabs', tabs, groups, true, versionName, config); | ||
return { tabs: tabsResult }; | ||
} | ||
if (groups.length) { | ||
@@ -260,3 +221,2 @@ const parsedGroups = filterGroupsByVersion(groups, versionName).map((group) => (Object.assign({ group: group.group, pages: group.pages }, (group.icon ? { icon: formatIcon(group.icon, group.iconType) } : {})))); | ||
if ((versions === null || versions === void 0 ? void 0 : versions.length) && !(globalVersions === null || globalVersions === void 0 ? void 0 : globalVersions.length)) { | ||
// divisions that match the versions | ||
const prefixes = versions.reduce((acc, version) => { | ||
@@ -273,10 +233,7 @@ const versionName = typeof version === 'string' ? version : version.name; | ||
var _a; | ||
if (typeof version === 'object' && 'href' in version) { | ||
return; | ||
} | ||
const versionName = typeof versions[index] === 'string' | ||
? version.version | ||
: ((_a = versions[index]) === null || _a === void 0 ? void 0 : _a.name) || version.language; | ||
if ('groups' in version && version.groups.length) { | ||
const updatedNavigationPerVersion = getUpdatedNavigation(version.groups, config, versionName); | ||
if ('groups' in version) { | ||
const updatedNavigationPerVersion = getUpdatedNavigation(version.groups, tabs, anchors, versionName, config); | ||
if (updatedNavigationPerVersion) { | ||
@@ -286,8 +243,2 @@ versionsResult[index] = Object.assign(Object.assign({}, _.omit(version, 'groups')), updatedNavigationPerVersion); | ||
} | ||
else { | ||
const updatedNavigationPerVersion = getUpdatedNavigation(groups, config, versionName); | ||
if (updatedNavigationPerVersion) { | ||
versionsResult[index] = Object.assign(Object.assign({}, _.omit(version, 'groups')), updatedNavigationPerVersion); | ||
} | ||
} | ||
}); | ||
@@ -300,3 +251,3 @@ const navigationConfig = (isLocale ? { languages: versionsResult } : { versions: versionsResult }); | ||
} | ||
const navigationConfig = (getUpdatedNavigation(groups, config) || { | ||
const navigationConfig = (getUpdatedNavigation(groups, tabs, anchors, undefined, config) || { | ||
groups: [], | ||
@@ -309,42 +260,1 @@ }); | ||
}; | ||
/** | ||
* Decide which division is most relevant to the top level navigation | ||
* 1. if tabs doesn't exist, return anchors, vice versa | ||
* 2. if both exist, return the most inclusive division | ||
* 2.1 if tabs are more inclusive, return tabs | ||
* 2.2 if anchors are more inclusive, return anchors | ||
*/ | ||
function findMostInclusiveDivision(tabs, anchors) { | ||
if (!(tabs === null || tabs === void 0 ? void 0 : tabs.length)) | ||
return 'anchors'; | ||
if (!(anchors === null || anchors === void 0 ? void 0 : anchors.length)) | ||
return 'tabs'; | ||
const inclusiveTabs = tabs.filter((tab) => { | ||
return anchors.some((anchor) => ensureLeadingSlash(tab.url).startsWith(ensureLeadingSlash(anchor.url))); | ||
}); | ||
const inclusiveAnchors = anchors.filter((anchor) => { | ||
return tabs.some((tab) => ensureLeadingSlash(anchor.url).startsWith(ensureLeadingSlash(tab.url))); | ||
}); | ||
// this means that there is a division that covers all paths | ||
if (inclusiveTabs.length === tabs.length) | ||
return 'tabs'; | ||
if (inclusiveAnchors.length === anchors.length) | ||
return 'anchors'; | ||
// compare the number of inclusive divisions | ||
return inclusiveTabs.length > inclusiveAnchors.length ? 'tabs' : 'anchors'; | ||
} | ||
function ensureLeadingSlash(path) { | ||
return path.startsWith('/') ? path : `/${path}`; | ||
} | ||
const getPrimaryConfig = (type, config) => { | ||
var _a, _b; | ||
if (type === 'anchor') { | ||
return Object.assign(Object.assign({}, (((_a = config === null || config === void 0 ? void 0 : config.topAnchor) === null || _a === void 0 ? void 0 : _a.name) ? { anchor: config.topAnchor.name } : DEFAULT_ANCHOR)), (((_b = config === null || config === void 0 ? void 0 : config.topAnchor) === null || _b === void 0 ? void 0 : _b.icon) | ||
? { icon: formatIcon(config.topAnchor.icon, config.topAnchor.iconType) } | ||
: {})); | ||
} | ||
return Object.assign({}, ((config === null || config === void 0 ? void 0 : config.primaryTab) | ||
? Object.assign({ tab: config.primaryTab.name }, (config.primaryTab.isDefaultHidden !== undefined && { | ||
hidden: config.primaryTab.isDefaultHidden, | ||
})) : DEFAULT_TAB)); | ||
}; |
{ | ||
"name": "@mintlify/validation", | ||
"version": "0.1.266", | ||
"version": "0.1.267", | ||
"description": "Validates mint.json files", | ||
@@ -38,3 +38,3 @@ "author": "Mintlify, Inc.", | ||
"dependencies": { | ||
"@mintlify/models": "0.0.166", | ||
"@mintlify/models": "0.0.167", | ||
"is-absolute-url": "^4.0.1", | ||
@@ -64,3 +64,3 @@ "lcm": "^0.0.3", | ||
}, | ||
"gitHead": "99a79cdcdc326ffa797e48a64056719f4cd8f528" | ||
"gitHead": "b64861e26b20aac2c3b3ed94a08b5b10451cfe7f" | ||
} |
Sorry, the diff of this file is not supported yet
1406678
185
33562
+ Added@mintlify/models@0.0.167(transitive)
- Removed@mintlify/models@0.0.166(transitive)
Updated@mintlify/models@0.0.167