Skip to content

Commit

Permalink
Fix sidebars
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshun committed Oct 9, 2018
1 parent 52b014a commit 48ff70e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
28 changes: 14 additions & 14 deletions v1/lib/server/__tests__/readMetadata.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,64 +36,64 @@ jest.mock(`${process.cwd()}/sidebar.json`, () => true, {virtual: true});

describe('readMetadata', () => {
describe('readSidebar', () => {
test('should verify sub category data and verify sort', () => {
const order = readSidebar(sidebarSubcategories);
test('should verify sub category data and verify order', () => {
const items = readSidebar(sidebarSubcategories);

// Put in this order to verify sort
const expectedOrder = [
// Put in this order to verify order
const expectedItems = [
{
id: 'doc1',
sort: 1,
order: 1,
category: 'First Category',
subcategory: null,
sidebar: 'docs',
},
{
id: 'doc2',
sort: 2,
order: 2,
category: 'First Category',
subcategory: null,
sidebar: 'docs',
},
{
id: 'doc3',
sort: 3,
order: 3,
category: 'Second Category',
subcategory: null,
sidebar: 'docs',
},
{
id: 'doc4',
sort: 4,
order: 4,
category: 'Second Category',
subcategory: 'First Subcategory',
sidebar: 'docs',
},
{
id: 'doc5',
sort: 5,
order: 5,
category: 'Second Category',
subcategory: null,
sidebar: 'docs',
},
{
id: 'doc6',
sort: 6,
order: 6,
category: 'Third Category',
subcategory: 'Second Subcategory',
sidebar: 'docs',
},
{
id: 'doc7',
sort: 7,
order: 7,
category: 'Third Category',
subcategory: 'Third Subcategory',
sidebar: 'docs',
},
];
expectedOrder.forEach((expectedItem, index) => {
const item = order[expectedItem.id];
expect(item.sort).toBe(expectedItem.sort);
expectedItems.forEach((expectedItem, index) => {
const item = items[expectedItem.id];
expect(item.order).toBe(expectedItem.order);
expect(item.category).toBe(expectedItem.category);
expect(item.subcategory).toBe(expectedItem.subcategory);
expect(item.sidebar).toBe(expectedItem.sidebar);
Expand Down
2 changes: 1 addition & 1 deletion v1/lib/server/readCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function readCategories(sidebar, allMetadata, languages) {
});

// Sort the metadata
metadatas.sort((a, b) => a.sort - b.sort);
metadatas.sort((a, b) => a.order - b.order);

// Store the correct sort of categories and sub categories for later
const sortedCategories = [];
Expand Down
19 changes: 8 additions & 11 deletions v1/lib/server/readMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,16 @@ function readSidebar(sidebars = {}) {
id: subcategoryItem,
category,
subcategory,
sort: sidebarItems.length + 1,
});
});
});
return;
}

sidebarItems.push({
id: categoryItem,
category,
subcategory: null,
sort: sidebarItems.length + 1,
});
});
});
Expand All @@ -99,15 +98,13 @@ function readSidebar(sidebars = {}) {
next = sidebarItems[i + 1].id;
}

order[item.id] = Object.assign(
{},
{
previous,
next,
sidebar,
},
item,
);
order[item.id] = {
previous,
next,
sidebar,
category: item.category,
subcategory: item.subcategory,
};
}
});

Expand Down
6 changes: 1 addition & 5 deletions v1/website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@
"Guides": [
"adding-blog",
"custom-pages",
"search",
"navigation",
"translation",
"versioning"
],
"Hello": {
"Bye": [
"search"
]
},
"API": [
"commands",
"doc-markdown",
Expand Down

0 comments on commit 48ff70e

Please sign in to comment.