Skip to content

Commit

Permalink
Update navigation menu generator to remove duplicates after sorting
Browse files Browse the repository at this point in the history
This means that the duplication filter will run based on the defined item priorities, giving config items precedence, fixing #1406
  • Loading branch information
caendesilva committed Oct 28, 2023
1 parent ddd432a commit 793d6b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static function create(): static
$menu = new static();

$menu->generate();
$menu->removeDuplicateItems();
$menu->sortByPriority();
$menu->removeDuplicateItems();

return $menu;
}
Expand Down
17 changes: 16 additions & 1 deletion packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,22 @@ public function test_duplicates_are_removed_when_adding_in_config_regardless_of_
$this->assertEquals($expected, $menu->items);
}

// TODO test when there are duplicates, config items take precedence
public function test_config_items_take_precedence_over_generated_items()
{
$this->file('_pages/foo.md');

config(['hyde.navigation.custom' => [NavItem::forLink('bar', 'Foo')]]);

$menu = NavigationMenu::create();

$expected = collect([
NavItem::fromRoute(Routes::get('index')),
NavItem::forLink('bar', 'Foo'),
]);

$this->assertCount(count($expected), $menu->items);
$this->assertEquals($expected, $menu->items);
}

public function test_documentation_pages_that_are_not_index_are_not_added_to_the_menu()
{
Expand Down

0 comments on commit 793d6b6

Please sign in to comment.