diff --git a/docs/guides-navigation.md b/docs/guides-navigation.md index 1cdb114e8f2d..ff8f2e3199cd 100644 --- a/docs/guides-navigation.md +++ b/docs/guides-navigation.md @@ -22,11 +22,9 @@ For example, creating an empty file such as `docs/getting-started.md` will enabl Suppose you add this to your document: ```yaml ---- id: intro title: Getting Started --- - My new content here.. ``` @@ -104,13 +102,17 @@ It is possible to add subcategories to a sidebar. Instead of using IDs as the co "My Example Category": [ "examples", { - "My Example Subcategory": [ + "type": "subcategory", + "label": "My Example Subcategory", + "ids": [ "my-examples", ... ] }, { - "My Next Subcategory": [ + "type": "subcategory", + "label": "My Next Subcategory", + "ids": [ "some-other-examples" ] }, @@ -253,8 +255,8 @@ The links in the top navigation bar get `siteNavItemActive` and `siteNavGroupAct The `siteNavGroupActive` class will be added to these links: -* `doc` links that belong to the same sidebar as the currently displayed document -* The blog link when a blog post, or the blog listing page is being displayed +- `doc` links that belong to the same sidebar as the currently displayed document +- The blog link when a blog post, or the blog listing page is being displayed These are two separate class names so you can have the active styles applied to either exact matches only or a bit more broadly for docs that belong together. If you don't want to make this distinction you can add both classes to the same CSS rule. diff --git a/v1/lib/server/__tests__/__fixtures__/sidebar-subcategories.js b/v1/lib/server/__tests__/__fixtures__/sidebar-subcategories.js index ff7583388275..c865e679a3ae 100644 --- a/v1/lib/server/__tests__/__fixtures__/sidebar-subcategories.js +++ b/v1/lib/server/__tests__/__fixtures__/sidebar-subcategories.js @@ -4,16 +4,22 @@ module.exports = { 'Second Category': [ 'doc3', { - 'First Subcategory': ['doc4'], + type: 'subcategory', + label: 'First Subcategory', + ids: ['doc4'], }, 'doc5', ], 'Third Category': [ { - 'Second Subcategory': ['doc6'], + type: 'subcategory', + label: 'Second Subcategory', + ids: ['doc6', 'doc7'], }, { - 'Third Subcategory': ['doc7'], + type: 'subcategory', + label: 'Third Subcategory', + ids: ['doc8'], }, ], }, diff --git a/v1/lib/server/__tests__/__snapshots__/readMetadata.test.js.snap b/v1/lib/server/__tests__/__snapshots__/readMetadata.test.js.snap index 0d5275559ccb..b06328f561ed 100644 --- a/v1/lib/server/__tests__/__snapshots__/readMetadata.test.js.snap +++ b/v1/lib/server/__tests__/__snapshots__/readMetadata.test.js.snap @@ -52,10 +52,18 @@ Object { }, "doc7": Object { "category": "Third Category", - "next": null, + "next": "doc8", "order": 7, "previous": "doc6", "sidebar": "docs", + "subcategory": "Second Subcategory", + }, + "doc8": Object { + "category": "Third Category", + "next": null, + "order": 8, + "previous": "doc7", + "sidebar": "docs", "subcategory": "Third Subcategory", }, } diff --git a/v1/lib/server/readMetadata.js b/v1/lib/server/readMetadata.js index c0244e92c091..c916809b8c2b 100644 --- a/v1/lib/server/readMetadata.js +++ b/v1/lib/server/readMetadata.js @@ -64,20 +64,23 @@ function readSidebar(sidebars = {}) { const categoryItems = categories[category]; categoryItems.forEach(categoryItem => { if (typeof categoryItem === 'object') { - Object.keys(categoryItem).forEach(subcategory => { - const subcategoryItems = categoryItem[subcategory]; - subcategoryItems.forEach(subcategoryItem => { - sidebarItems.push({ - id: subcategoryItem, - category, - subcategory, - order: sidebarItems.length + 1, + switch (categoryItem.type) { + case 'subcategory': + categoryItem.ids.forEach(subcategoryItem => { + sidebarItems.push({ + id: subcategoryItem, + category, + subcategory: categoryItem.label, + order: sidebarItems.length + 1, + }); }); - }); - }); - return; + return; + default: + return; + } } + // Is a regular id value. sidebarItems.push({ id: categoryItem, category,