Skip to content

Commit 4fc7b9e

Browse files
authored
Merge pull request #1583 from hydephp/normalize-navigation-configuration-api
[2.x] Breaking: Change configuration option `docs.sidebar_order` to `docs.sidebar.order`
2 parents 0490bf6 + 7b8e90b commit 4fc7b9e

File tree

10 files changed

+85
-81
lines changed

10 files changed

+85
-81
lines changed

config/docs.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@
3333
// Should the sidebar footer be shown? You can also set this to a string
3434
// of Markdown to show in the footer. Set to `false` to disable.
3535
'footer' => true,
36-
],
37-
38-
/*
39-
|--------------------------------------------------------------------------
40-
| Sidebar Page Order
41-
|--------------------------------------------------------------------------
42-
|
43-
| In the generated Documentation pages the navigation links in the sidebar
44-
| default to sort alphabetically. You can reorder the page identifiers
45-
| in the list below, and the links will get sorted in that order.
46-
|
47-
| The items will get a priority of 500 plus the order its found in the list.
48-
| Pages without a priority will fall back to the default priority of 999.
49-
|
50-
| You can also set explicit priorities in front matter or by specifying
51-
| a value to the array key in the list to override the inferred value.
52-
|
53-
*/
5436

55-
'sidebar_order' => [
56-
'readme',
57-
'installation',
58-
'getting-started',
37+
/*
38+
|--------------------------------------------------------------------------
39+
| Sidebar Page Order
40+
|--------------------------------------------------------------------------
41+
|
42+
| In the generated Documentation pages the navigation links in the sidebar
43+
| default to sort alphabetically. You can reorder the page identifiers
44+
| in the list below, and the links will get sorted in that order.
45+
|
46+
| The items will get a priority of 500 plus the order its found in the list.
47+
| Pages without a priority will fall back to the default priority of 999.
48+
|
49+
| You can also set explicit priorities in front matter or by specifying
50+
| a value to the array key in the list to override the inferred value.
51+
|
52+
*/
53+
54+
'order' => [
55+
'readme',
56+
'installation',
57+
'getting-started',
58+
],
5959
],
6060

6161
/*

docs/creating-content/documentation-pages.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,12 @@ To quickly arrange the order of items in the sidebar, you can reorder the page i
223223
Link items without an entry here will fall back to the default priority of 999, putting them last.
224224

225225
```php
226-
'sidebar_order' => [
227-
'readme',
228-
'installation',
229-
'getting-started',
226+
'sidebar' => [
227+
'order' => [
228+
'readme',
229+
'installation',
230+
'getting-started',
231+
],
230232
]
231233
```
232234

docs/digging-deeper/customization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ Learn more in the [Navigation Menu](navigation) documentation.
259259

260260
#### Customizing the documentation sidebar
261261

262-
- To customize the sidebar, use the setting `sidebar_order` in the `docs.php` config.
262+
- To customize the sidebar, use the setting `sidebar.order` in the `docs.php` config.
263263
- When customizing the sidebar, can use the route key, or just the [page identifier](core-concepts#page-identifiers) of the page.
264264

265265
Learn more in the [Documentation Pages](documentation-pages) documentation.

docs/digging-deeper/navigation.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ Next up, let's look at how to customize the navigation menus using the config fi
122122
- To customize the navigation menu, use the setting `navigation.order` in the `hyde.php` config.
123123
- When customizing the navigation menu, you should use the [route key](core-concepts#route-keys) of the page.
124124

125-
- To customize the sidebar, use the setting `sidebar_order` in the `docs.php` config.
125+
- To customize the sidebar, use the setting `sidebar.order` in the `docs.php` config.
126126
- When customizing the sidebar, can use the route key, or just the [page identifier](core-concepts#page-identifiers) of the page.
127127

128128
### Changing the priorities
129129

130-
The `navigation.order` and `sidebar_order` settings allow you to customize the order of the pages in the navigation menus.
130+
The `navigation.order` and `sidebar.order` settings allow you to customize the order of the pages in the navigation menus.
131131

132132
#### Basic syntax for changing the priorities
133133

@@ -149,10 +149,12 @@ The offset is added to make it easier to place pages earlier in the list using f
149149
```php
150150
// filepath: config/docs.php
151151
152-
'sidebar_order' => [
153-
'readme', // Gets priority 500
154-
'installation', // Gets priority 501
155-
'getting-started', // Gets priority 502
152+
'sidebar' => [
153+
'order' => [
154+
'readme', // Gets priority 500
155+
'installation', // Gets priority 501
156+
'getting-started', // Gets priority 502
157+
]
156158
]
157159
```
158160

@@ -175,10 +177,12 @@ You can also specify explicit priorities by adding a value to the array key:
175177
```php
176178
// filepath: config/docs.php
177179
178-
'sidebar_order' => [
179-
'readme' => 10, // Gets priority 10
180-
'installation' => 15, // Gets priority 15
181-
'getting-started' => 20, // Gets priority 20
180+
'sidebar' => [
181+
'order' => [
182+
'readme' => 10, // Gets priority 10
183+
'installation' => 15, // Gets priority 15
184+
'getting-started' => 20, // Gets priority 20
185+
]
182186
]
183187
```
184188

packages/framework/config/docs.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@
3333
// Should the sidebar footer be shown? You can also set this to a string
3434
// of Markdown to show in the footer. Set to `false` to disable.
3535
'footer' => true,
36-
],
37-
38-
/*
39-
|--------------------------------------------------------------------------
40-
| Sidebar Page Order
41-
|--------------------------------------------------------------------------
42-
|
43-
| In the generated Documentation pages the navigation links in the sidebar
44-
| default to sort alphabetically. You can reorder the page identifiers
45-
| in the list below, and the links will get sorted in that order.
46-
|
47-
| The items will get a priority of 500 plus the order its found in the list.
48-
| Pages without a priority will fall back to the default priority of 999.
49-
|
50-
| You can also set explicit priorities in front matter or by specifying
51-
| a value to the array key in the list to override the inferred value.
52-
|
53-
*/
5436

55-
'sidebar_order' => [
56-
'readme',
57-
'installation',
58-
'getting-started',
37+
/*
38+
|--------------------------------------------------------------------------
39+
| Sidebar Page Order
40+
|--------------------------------------------------------------------------
41+
|
42+
| In the generated Documentation pages the navigation links in the sidebar
43+
| default to sort alphabetically. You can reorder the page identifiers
44+
| in the list below, and the links will get sorted in that order.
45+
|
46+
| The items will get a priority of 500 plus the order its found in the list.
47+
| Pages without a priority will fall back to the default priority of 999.
48+
|
49+
| You can also set explicit priorities in front matter or by specifying
50+
| a value to the array key in the list to override the inferred value.
51+
|
52+
*/
53+
54+
'order' => [
55+
'readme',
56+
'installation',
57+
'getting-started',
58+
],
5959
],
6060

6161
/*

packages/framework/src/Framework/Factories/NavigationDataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private function searchForPriorityInConfigs(): ?int
160160
private function searchForPriorityInSidebarConfig(): ?int
161161
{
162162
/** @var array<string>|array<string, int> $config */
163-
$config = Config::getArray('docs.sidebar_order', []);
163+
$config = Config::getArray('docs.sidebar.order', []);
164164

165165
return
166166
// For consistency with the navigation config.

packages/framework/src/Framework/Features/Navigation/NavigationMenuGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected function searchForGroupLabelInConfig(string $groupKey): ?string
182182

183183
protected function searchForGroupPriorityInConfig(string $groupKey): ?int
184184
{
185-
$key = $this->generatesSidebar ? 'docs.sidebar_order' : 'hyde.navigation.order';
185+
$key = $this->generatesSidebar ? 'docs.sidebar.order' : 'hyde.navigation.order';
186186

187187
return Config::getArray($key, [])[$groupKey] ?? null;
188188
}

packages/framework/tests/Feature/AutomaticNavigationConfigurationsTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,15 @@ public function testSidebarWithFrontMatterGroupAndCategory()
745745

746746
public function testSidebarWithConfigOrder()
747747
{
748-
// TODO should be sidebar.order instead of docs.sidebar_order
749-
750-
config(['docs.sidebar_order' => ['first', 'second', 'third']]);
748+
config(['docs.sidebar.order' => ['first', 'second', 'third']]);
751749

752750
$this->assertSidebarEquals(['First', 'Second', 'Third'], [
753751
new DocumentationPage('first'),
754752
new DocumentationPage('second'),
755753
new DocumentationPage('third'),
756754
]);
757755

758-
config(['docs.sidebar_order' => ['third', 'second', 'first']]);
756+
config(['docs.sidebar.order' => ['third', 'second', 'first']]);
759757

760758
$this->assertSidebarEquals(['Third', 'Second', 'First'], [
761759
new DocumentationPage('first'),
@@ -776,7 +774,7 @@ public function testSidebarWithConfigOrderHasInferredPriorities()
776774
new DocumentationPage('third'),
777775
]);
778776

779-
config(['docs.sidebar_order' => ['first', 'second', 'third']]);
777+
config(['docs.sidebar.order' => ['first', 'second', 'third']]);
780778

781779
$this->assertSidebarEquals([
782780
['priority' => 500],
@@ -791,23 +789,23 @@ public function testSidebarWithConfigOrderHasInferredPriorities()
791789

792790
public function testSidebarWithExplicitConfigOrder()
793791
{
794-
config(['docs.sidebar_order' => ['first' => 1, 'second' => 2, 'third' => 3]]);
792+
config(['docs.sidebar.order' => ['first' => 1, 'second' => 2, 'third' => 3]]);
795793

796794
$this->assertSidebarEquals(['First', 'Second', 'Third'], [
797795
new DocumentationPage('first'),
798796
new DocumentationPage('second'),
799797
new DocumentationPage('third'),
800798
]);
801799

802-
config(['docs.sidebar_order' => ['first' => 3, 'second' => 2, 'third' => 1]]);
800+
config(['docs.sidebar.order' => ['first' => 3, 'second' => 2, 'third' => 1]]);
803801

804802
$this->assertSidebarEquals(['Third', 'Second', 'First'], [
805803
new DocumentationPage('first'),
806804
new DocumentationPage('second'),
807805
new DocumentationPage('third'),
808806
]);
809807

810-
config(['docs.sidebar_order' => ['first' => 1, 'second' => 2, 'third' => 3]]);
808+
config(['docs.sidebar.order' => ['first' => 1, 'second' => 2, 'third' => 3]]);
811809

812810
$this->assertSidebarEquals([
813811
['label' => 'First', 'priority' => 1],
@@ -822,7 +820,7 @@ public function testSidebarWithExplicitConfigOrder()
822820

823821
public function testSidebarWithMixedConfigOrders()
824822
{
825-
config(['docs.sidebar_order' => ['foo', 'bar' => 650]]);
823+
config(['docs.sidebar.order' => ['foo', 'bar' => 650]]);
826824

827825
$this->assertSidebarEquals([
828826
['label' => 'Foo', 'priority' => 500],
@@ -1059,7 +1057,7 @@ public function testSidebarGroupsAreSortedByLowestFoundPriorityInEachGroupUnless
10591057
new DocumentationPage('baz', ['navigation.group' => 'c', 'navigation.priority' => 10]),
10601058
]);
10611059

1062-
config(['docs.sidebar_order' => ['a' => 5]]);
1060+
config(['docs.sidebar.order' => ['a' => 5]]);
10631061

10641062
$this->assertSidebarEquals([
10651063
'A', 'C', 'B',
@@ -1117,7 +1115,7 @@ public function testMainNavigationDropdownPriorityCanBeSetInConfigUsingDiffering
11171115

11181116
public function testSidebarGroupPriorityCanBeSetInConfig()
11191117
{
1120-
config(['docs.sidebar_order' => ['foo' => 500]]);
1118+
config(['docs.sidebar.order' => ['foo' => 500]]);
11211119

11221120
$this->assertSidebarEquals(
11231121
[['label' => 'Foo', 'priority' => 500]],
@@ -1127,7 +1125,7 @@ public function testSidebarGroupPriorityCanBeSetInConfig()
11271125

11281126
public function testSidebarGroupPriorityCanBeSetInConfigUsingDifferingCases()
11291127
{
1130-
config(['docs.sidebar_order' => ['hello-world' => 500]]);
1128+
config(['docs.sidebar.order' => ['hello-world' => 500]]);
11311129

11321130
$expected = [['label' => 'Hello World', 'priority' => 500]];
11331131
$this->assertSidebarEquals($expected, [new DocumentationPage('Hello World/bar')]);

packages/framework/tests/Feature/Services/DocumentationSidebarTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testFilesWithFrontMatterHiddenSetToTrueAreRemovedFromSidebar()
7777

7878
public function testSidebarIsOrderedAlphabeticallyWhenNoOrderIsSetInConfig()
7979
{
80-
Config::set('docs.sidebar_order', []);
80+
Config::set('docs.sidebar.order', []);
8181
Filesystem::touch('_docs/a.md');
8282
Filesystem::touch('_docs/b.md');
8383
Filesystem::touch('_docs/c.md');
@@ -94,7 +94,7 @@ public function testSidebarIsOrderedAlphabeticallyWhenNoOrderIsSetInConfig()
9494

9595
public function testSidebarIsOrderedByPriorityWhenPriorityIsSetInConfig()
9696
{
97-
Config::set('docs.sidebar_order', [
97+
Config::set('docs.sidebar.order', [
9898
'c',
9999
'b',
100100
'a',
@@ -124,14 +124,14 @@ public function testSidebarItemPrioritySetInConfigOverridesFrontMatter()
124124
{
125125
$this->makePage('foo', ['navigation.priority' => 25]);
126126

127-
Config::set('docs.sidebar_order', ['foo']);
127+
Config::set('docs.sidebar.order', ['foo']);
128128

129129
$this->assertEquals(25, NavigationMenuGenerator::handle(DocumentationSidebar::class)->getItems()->first()->getPriority());
130130
}
131131

132132
public function testSidebarPrioritiesCanBeSetInBothFrontMatterAndConfig()
133133
{
134-
Config::set('docs.sidebar_order', [
134+
Config::set('docs.sidebar.order', [
135135
'first',
136136
'third',
137137
'second',

packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testSearchForPriorityInNavigationConfigForMarkdownPageSupportsMi
7474

7575
public function testSearchForPriorityInNavigationConfigForDocumentationPageWithListConfig()
7676
{
77-
self::mockConfig(['docs.sidebar_order' => [
77+
self::mockConfig(['docs.sidebar.order' => [
7878
'foo' => 15,
7979
'bar' => 10,
8080
]]);
@@ -88,7 +88,7 @@ public function testSearchForPriorityInNavigationConfigForDocumentationPageWithL
8888

8989
public function testSearchForPriorityInNavigationConfigForDocumentationPageWithKeyedConfig()
9090
{
91-
self::mockConfig(['docs.sidebar_order' => [
91+
self::mockConfig(['docs.sidebar.order' => [
9292
'foo',
9393
'bar' => 10,
9494
'baz',
@@ -109,7 +109,7 @@ public function testSearchForPriorityInNavigationConfigForDocumentationPageWithK
109109

110110
public function testSearchForPriorityInNavigationConfigForDocumentationPageSupportsMixingKeyedAndListConfig()
111111
{
112-
self::mockConfig(['docs.sidebar_order' => [
112+
self::mockConfig(['docs.sidebar.order' => [
113113
'foo',
114114
'bar' => 10,
115115
'baz',
@@ -130,7 +130,7 @@ public function testSearchForPriorityInNavigationConfigForDocumentationPageSuppo
130130

131131
public function testRouteKeysCanBeUsedForDocumentationSidebarPriorities()
132132
{
133-
self::mockConfig(['docs.sidebar_order' => [
133+
self::mockConfig(['docs.sidebar.order' => [
134134
'key/foo',
135135
'key/bar',
136136
'baz',

0 commit comments

Comments
 (0)