Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/documentation-framework/components/sideNav/sideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const getIsActive = (location, section, subsection = null) => {
return location.pathname.startsWith(`${process.env.pathPrefix}${slug}`);
}

const defaultValue = 50;

const NavItem = ({ text, href }) => {
const isMobileView = window.innerWidth < Number.parseInt(globalBreakpointXl.value, 10);
return (
Expand Down Expand Up @@ -67,9 +69,14 @@ const ExpandableNav = ({groupedRoutes, location, section, subsection = null}) =>
}}
>
{Object.entries(routes || {})
.filter(([id, { hideNavItem }]) => !Boolean(hideNavItem) && (id !== 'isSubsection'))
.map(([id, { slug, isSubsection = false }]) => ({ text: id, href: slug, isSubsection }))
.sort(({ text: text1 }, { text: text2 }) => text1.localeCompare(text2))
.filter(([id, navObj]) => !Boolean(navObj.hideNavItem) && (Object.entries(navObj).length > 0))
.map(([id, { slug, isSubsection = false, sortValue = defaultValue, subsectionSortValue = defaultValue }]) => ({ text: id, href: slug, isSubsection, sortValue: (isSubsection ? subsectionSortValue : sortValue) }))
.sort(({text: text1, sortValue: sortValue1}, {text: text2, sortValue: sortValue2}) => {
if (sortValue1 === sortValue2) {
return text1.localeCompare(text2);
}
return sortValue1 > sortValue2 ? 1 : -1;
})
.map(navObj => navObj.isSubsection
? ExpandableNav({groupedRoutes, location, section, subsection: navObj.text})
: NavItem(navObj)
Expand Down
23 changes: 19 additions & 4 deletions packages/documentation-framework/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const routes = {
...generatedRoutes
};

const defaultOrder = 50;

for (let route in routes) {
const pageData = routes[route];
if (pageData.SyncComponent) {
Expand All @@ -28,7 +30,7 @@ const isNull = o => o === null || o === undefined;
const groupedRoutes = Object.entries(routes)
.filter(([_slug, { id, section }]) => !isNull(id) && !isNull(section))
.reduce((accum, [slug, pageData]) => {
const { section, subsection = null, id, title, source, katacodaLayout, hideNavItem, relPath } = pageData;
const { section, subsection = null, id, title, source, katacodaLayout, hideNavItem, relPath, sortValue = null, subsectionSortValue = null } = pageData;
pageData.slug = slug;
// add section to groupedRoutes obj if not yet created
accum[section] = accum[section] || {};
Expand All @@ -42,7 +44,9 @@ const groupedRoutes = Object.entries(routes)
sources: [],
katacodaLayout,
hideNavItem,
relPath
relPath,
...(sortValue && { sortValue }),
...(subsectionSortValue && { subsectionSortValue })
}
// add page to groupedRoutes obj section or subsection
if (subsection) {
Expand All @@ -52,10 +56,21 @@ const groupedRoutes = Object.entries(routes)
// add page to subsection
accum[section][subsection][id] = accum[section][subsection][id] || data;
accum[section][subsection][id].sources.push(pageData);
// nav item ordering
if (sortValue) {
accum[section][subsection].sortValue = sortValue;
}
if (subsectionSortValue) {
accum[section][subsection].subsectionSortValue = subsectionSortValue;
}
} else {
// add page to section
accum[section][id] = accum[section][id] || data;
accum[section][id].sources.push(pageData);
// nav item ordering
if (sortValue) {
accum[section][id].sortValue = sortValue;
}
}

return accum;
Expand All @@ -73,7 +88,6 @@ const sourceOrder = {
'design-guidelines': 99,
'accessibility': 100
};
const defaultOrder = 50;

const sortSources = ({ source: s1 }, { source: s2 }) => {
const s1Index = sourceOrder[s1] || defaultOrder;
Expand Down Expand Up @@ -108,7 +122,8 @@ Object.entries(groupedRoutes)
// Loop through each page in expandable subsection
if (pageData.isSubsection) {
Object.entries(pageData).map(([section, ids]) => {
if (section !== 'isSubsection') {
// only push nested page objects
if (ids && ids?.id) {
pageDataArr.push(ids);
}
})
Expand Down
10 changes: 9 additions & 1 deletion packages/documentation-framework/scripts/md/parseMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ function toReactComponent(mdFilePath, source, buildMode) {
if (frontmatter.hideNavItem) {
pageData.hideNavItem = frontmatter.hideNavItem;
}
if (frontmatter.sortValue) {
pageData.sortValue = frontmatter.sortValue;
}
if (frontmatter.subsectionSortValue) {
pageData.subsectionSortValue = frontmatter.subsectionSortValue;
}
})
// Delete HTML comments
.use(require('./remove-comments'))
Expand Down Expand Up @@ -269,7 +275,9 @@ function sourceMDFile(file, source, buildMode) {
source: pageData.source,
tabName: pageData.tabName,
...(pageData.katacodaLayout && { katacodaLayout: pageData.katacodaLayout }),
...(pageData.hideNavItem && { hideNavItem: pageData.hideNavItem })
...(pageData.hideNavItem && { hideNavItem: pageData.hideNavItem }),
...(pageData.sortValue && { sortValue: pageData.sortValue }),
...(pageData.subsectionSortValue && { subsectionSortValue: pageData.subsectionSortValue })
};
}
}
Expand Down