@patternfly/documentation-framework 1.7.0 → 1.8.1

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 1.8.1 (2023-02-20)
7
+
8
+ **Note:** Version bump only for package @patternfly/documentation-framework
9
+
10
+
11
+
12
+
13
+
14
+ # 1.8.0 (2023-02-09)
15
+
16
+
17
+ ### Features
18
+
19
+ * **docs:** enabled manual ordering of sidenav ([#3403](https://github.com/patternfly/patternfly-org/issues/3403)) ([b630ed9](https://github.com/patternfly/patternfly-org/commit/b630ed9e7062e1302d58793bfec65d49da7764d3))
20
+
21
+
22
+
23
+
24
+
6
25
  # 1.7.0 (2023-02-09)
7
26
 
8
27
 
@@ -12,6 +12,8 @@ const getIsActive = (location, section, subsection = null) => {
12
12
  return location.pathname.startsWith(`${process.env.pathPrefix}${slug}`);
13
13
  }
14
14
 
15
+ const defaultValue = 50;
16
+
15
17
  const NavItem = ({ text, href }) => {
16
18
  const isMobileView = window.innerWidth < Number.parseInt(globalBreakpointXl.value, 10);
17
19
  return (
@@ -67,9 +69,14 @@ const ExpandableNav = ({groupedRoutes, location, section, subsection = null}) =>
67
69
  }}
68
70
  >
69
71
  {Object.entries(routes || {})
70
- .filter(([id, { hideNavItem }]) => !Boolean(hideNavItem) && (id !== 'isSubsection'))
71
- .map(([id, { slug, isSubsection = false }]) => ({ text: id, href: slug, isSubsection }))
72
- .sort(({ text: text1 }, { text: text2 }) => text1.localeCompare(text2))
72
+ .filter(([id, navObj]) => !Boolean(navObj.hideNavItem) && (Object.entries(navObj).length > 0))
73
+ .map(([id, { slug, isSubsection = false, sortValue = defaultValue, subsectionSortValue = defaultValue }]) => ({ text: id, href: slug, isSubsection, sortValue: (isSubsection ? subsectionSortValue : sortValue) }))
74
+ .sort(({text: text1, sortValue: sortValue1}, {text: text2, sortValue: sortValue2}) => {
75
+ if (sortValue1 === sortValue2) {
76
+ return text1.localeCompare(text2);
77
+ }
78
+ return sortValue1 > sortValue2 ? 1 : -1;
79
+ })
73
80
  .map(navObj => navObj.isSubsection
74
81
  ? ExpandableNav({groupedRoutes, location, section, subsection: navObj.text})
75
82
  : NavItem(navObj)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@patternfly/documentation-framework",
3
3
  "description": "A framework to build documentation for PatternFly.",
4
- "version": "1.7.0",
4
+ "version": "1.8.1",
5
5
  "author": "Red Hat",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -84,5 +84,5 @@
84
84
  "react": "^16.8.0 || ^17.0.0",
85
85
  "react-dom": "^16.8.0 || ^17.0.0"
86
86
  },
87
- "gitHead": "a9a48b143a7a72b044d35960fee0c8122a117b9c"
87
+ "gitHead": "40d1a8a9f0ee643cc2844df4cd5153813c091177"
88
88
  }
package/routes.js CHANGED
@@ -9,6 +9,8 @@ const routes = {
9
9
  ...generatedRoutes
10
10
  };
11
11
 
12
+ const defaultOrder = 50;
13
+
12
14
  for (let route in routes) {
13
15
  const pageData = routes[route];
14
16
  if (pageData.SyncComponent) {
@@ -28,7 +30,7 @@ const isNull = o => o === null || o === undefined;
28
30
  const groupedRoutes = Object.entries(routes)
29
31
  .filter(([_slug, { id, section }]) => !isNull(id) && !isNull(section))
30
32
  .reduce((accum, [slug, pageData]) => {
31
- const { section, subsection = null, id, title, source, katacodaLayout, hideNavItem, relPath } = pageData;
33
+ const { section, subsection = null, id, title, source, katacodaLayout, hideNavItem, relPath, sortValue = null, subsectionSortValue = null } = pageData;
32
34
  pageData.slug = slug;
33
35
  // add section to groupedRoutes obj if not yet created
34
36
  accum[section] = accum[section] || {};
@@ -42,7 +44,9 @@ const groupedRoutes = Object.entries(routes)
42
44
  sources: [],
43
45
  katacodaLayout,
44
46
  hideNavItem,
45
- relPath
47
+ relPath,
48
+ ...(sortValue && { sortValue }),
49
+ ...(subsectionSortValue && { subsectionSortValue })
46
50
  }
47
51
  // add page to groupedRoutes obj section or subsection
48
52
  if (subsection) {
@@ -52,10 +56,21 @@ const groupedRoutes = Object.entries(routes)
52
56
  // add page to subsection
53
57
  accum[section][subsection][id] = accum[section][subsection][id] || data;
54
58
  accum[section][subsection][id].sources.push(pageData);
59
+ // nav item ordering
60
+ if (sortValue) {
61
+ accum[section][subsection].sortValue = sortValue;
62
+ }
63
+ if (subsectionSortValue) {
64
+ accum[section][subsection].subsectionSortValue = subsectionSortValue;
65
+ }
55
66
  } else {
56
67
  // add page to section
57
68
  accum[section][id] = accum[section][id] || data;
58
69
  accum[section][id].sources.push(pageData);
70
+ // nav item ordering
71
+ if (sortValue) {
72
+ accum[section][id].sortValue = sortValue;
73
+ }
59
74
  }
60
75
 
61
76
  return accum;
@@ -73,7 +88,6 @@ const sourceOrder = {
73
88
  'design-guidelines': 99,
74
89
  'accessibility': 100
75
90
  };
76
- const defaultOrder = 50;
77
91
 
78
92
  const sortSources = ({ source: s1 }, { source: s2 }) => {
79
93
  const s1Index = sourceOrder[s1] || defaultOrder;
@@ -108,7 +122,8 @@ Object.entries(groupedRoutes)
108
122
  // Loop through each page in expandable subsection
109
123
  if (pageData.isSubsection) {
110
124
  Object.entries(pageData).map(([section, ids]) => {
111
- if (section !== 'isSubsection') {
125
+ // only push nested page objects
126
+ if (ids && ids?.id) {
112
127
  pageDataArr.push(ids);
113
128
  }
114
129
  })
@@ -127,6 +127,12 @@ function toReactComponent(mdFilePath, source, buildMode) {
127
127
  if (frontmatter.hideNavItem) {
128
128
  pageData.hideNavItem = frontmatter.hideNavItem;
129
129
  }
130
+ if (frontmatter.sortValue) {
131
+ pageData.sortValue = frontmatter.sortValue;
132
+ }
133
+ if (frontmatter.subsectionSortValue) {
134
+ pageData.subsectionSortValue = frontmatter.subsectionSortValue;
135
+ }
130
136
  })
131
137
  // Delete HTML comments
132
138
  .use(require('./remove-comments'))
@@ -269,7 +275,9 @@ function sourceMDFile(file, source, buildMode) {
269
275
  source: pageData.source,
270
276
  tabName: pageData.tabName,
271
277
  ...(pageData.katacodaLayout && { katacodaLayout: pageData.katacodaLayout }),
272
- ...(pageData.hideNavItem && { hideNavItem: pageData.hideNavItem })
278
+ ...(pageData.hideNavItem && { hideNavItem: pageData.hideNavItem }),
279
+ ...(pageData.sortValue && { sortValue: pageData.sortValue }),
280
+ ...(pageData.subsectionSortValue && { subsectionSortValue: pageData.subsectionSortValue })
273
281
  };
274
282
  }
275
283
  }