Skip to content

Commit

Permalink
Change format
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Oct 10, 2018
1 parent bad52af commit b6495d0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
14 changes: 8 additions & 6 deletions docs/guides-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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..
```

Expand Down Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -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.

Expand Down
12 changes: 9 additions & 3 deletions v1/lib/server/__tests__/__fixtures__/sidebar-subcategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
],
},
Expand Down
10 changes: 9 additions & 1 deletion v1/lib/server/__tests__/__snapshots__/readMetadata.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
Expand Down
25 changes: 14 additions & 11 deletions v1/lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b6495d0

Please sign in to comment.