@uniweb/core 0.7.26 → 0.7.27
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/package.json +1 -1
- package/src/website.js +39 -0
package/package.json
CHANGED
package/src/website.js
CHANGED
|
@@ -1173,6 +1173,45 @@ export default class Website {
|
|
|
1173
1173
|
return filteredPages.map(buildPageInfo)
|
|
1174
1174
|
}
|
|
1175
1175
|
|
|
1176
|
+
/**
|
|
1177
|
+
* Get the page tree for the branch a route sits in.
|
|
1178
|
+
*
|
|
1179
|
+
* A sidebar shows one branch of a site, not the whole thing: under /docs it
|
|
1180
|
+
* lists the documentation, and under a different top-level section it would
|
|
1181
|
+
* list that instead. Every documentation shell built on this framework has
|
|
1182
|
+
* hand-written the same narrowing, so it lives here — it is a question about
|
|
1183
|
+
* the page graph, with no React and no DOM in it.
|
|
1184
|
+
*
|
|
1185
|
+
* Answers the branch's children when it has any, the branch itself when it
|
|
1186
|
+
* is a leaf, and the whole hierarchy when the route matches no branch (the
|
|
1187
|
+
* site root, most often). The pages come back in the order the build settled
|
|
1188
|
+
* on; `pages:` lists are resolved at build time, so there is nothing to sort.
|
|
1189
|
+
*
|
|
1190
|
+
* @param {Object} [options]
|
|
1191
|
+
* @param {string} options.route - The active route, e.g. '/docs/reference/cli'
|
|
1192
|
+
* @param {string} [options.for] - Layout area being filled ('left', 'header', …).
|
|
1193
|
+
* Checked against each page's `hideIn`, so a page can sit out of this rail
|
|
1194
|
+
* while staying in the menu. Name the area the tree is actually for.
|
|
1195
|
+
* @param {boolean} [options.includeHidden=false] - Include unpublished pages
|
|
1196
|
+
* @returns {Array<Object>} Page info objects, nested
|
|
1197
|
+
*
|
|
1198
|
+
* @example
|
|
1199
|
+
* // In a sidebar component rendered into the `left` layout area
|
|
1200
|
+
* const pages = website.getBranchHierarchy({ route: location.pathname, for: 'left' })
|
|
1201
|
+
*/
|
|
1202
|
+
getBranchHierarchy({ route = '', for: navType, includeHidden = false } = {}) {
|
|
1203
|
+
const normalize = (value) => (value || '').replace(/^\/+/, '').replace(/\/+$/, '')
|
|
1204
|
+
|
|
1205
|
+
const all = this.getPageHierarchy({ for: navType, includeHidden })
|
|
1206
|
+
const branchName = normalize(route).split('/')[0]
|
|
1207
|
+
if (!branchName) return all
|
|
1208
|
+
|
|
1209
|
+
const branch = all.find((page) => normalize(page.route) === branchName)
|
|
1210
|
+
if (!branch) return all
|
|
1211
|
+
|
|
1212
|
+
return branch.children?.length ? branch.children : [branch]
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1176
1215
|
/**
|
|
1177
1216
|
* Get pages for header navigation
|
|
1178
1217
|
* Convenience method equivalent to getPageHierarchy({ for: 'header' })
|