Skip to content

Commit

Permalink
Support both route keys and identifiers for specifying sidebar order
Browse files Browse the repository at this point in the history
- Supports route keys for consistency with the navigation config.
- Supports identifiers for backwards compatibility and ease of use, as the route key prefix is redundant due to it being the same for all documentation pages.
  • Loading branch information
caendesilva committed Nov 7, 2023
1 parent 1a4b498 commit 4622ee3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ private function searchForPriorityInSidebarConfig(): ?int
/** @var array<string>|array<string, int> $config */
$config = Config::getArray('docs.sidebar_order', []);

return $this->parseNavigationPriorityConfig($config, 'identifier');
return $this->parseNavigationPriorityConfig($config, 'routeKey') // For consistency with the navigation config.
?? $this->parseNavigationPriorityConfig($config, 'identifier'); // For backwards compatibility and ease of use
}

private function searchForPriorityInNavigationConfig(): ?int
Expand Down
18 changes: 18 additions & 0 deletions packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ public function testSearchForPriorityInNavigationConfigForDocumentationPageSuppo
$this->assertSame(999, $factory->makePriority());
}

public function testRouteKeysCanBeUsedForDocumentationSidebarPriorities()
{
self::mockConfig(['docs.sidebar_order' => [
'key/foo',
'key/bar',
'baz',
]]);

$factory = new NavigationConfigTestClass($this->makeCoreDataObject('foo', routeKey: 'key/foo', pageClass: DocumentationPage::class));
$this->assertSame(500, $factory->makePriority());

$factory = new NavigationConfigTestClass($this->makeCoreDataObject('bar', routeKey: 'key/bar', pageClass: DocumentationPage::class));
$this->assertSame(501, $factory->makePriority());

$factory = new NavigationConfigTestClass($this->makeCoreDataObject('baz', routeKey: 'key', pageClass: DocumentationPage::class));
$this->assertSame(502, $factory->makePriority());
}

protected function makeCoreDataObject(string $identifier = '', string $routeKey = '', string $pageClass = MarkdownPage::class): CoreDataObject
{
return new CoreDataObject(new FrontMatter(), new Markdown(), $pageClass, $identifier, '', '', $routeKey);
Expand Down

0 comments on commit 4622ee3

Please sign in to comment.