Skip to content

Commit

Permalink
Add sidebar config offset, fix #307
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 15, 2022
1 parent 75a5c99 commit 5854701
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Models/DocumentationSidebarItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ protected function findPriorityInConfig(string $slug): int
return 500;
}

return array_search($slug, $orderIndexArray); // + 250?
return array_search($slug, $orderIndexArray) + 250;

// Adding 250 makes so that pages with a front matter priority that is lower
// can be shown first. It's lower than the fallback of 500 so that they
// still come first. This is all to make it easier to mix priorities.
}

public function isHidden(): bool
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Services/DocumentationSidebarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function test_sidebar_item_priority_set_in_config_overrides_front_matter(
$this->assertEquals(25, DocumentationSidebarService::get()->first()->priority);
}

public function test_both_sidebar_priority_setting_methods_can_be_used()
public function test_sidebar_priorities_can_be_set_in_both_front_matter_and_config()
{
Config::set('hyde.documentationPageOrder', [
'first',
Expand All @@ -142,7 +142,7 @@ public function test_both_sidebar_priority_setting_methods_can_be_used()
touch(Hyde::path('_docs/first.md'));
touch(Hyde::path('_docs/second.md'));
file_put_contents(Hyde::path('_docs/third.md'),
(new ConvertsArrayToFrontMatter)->execute(['priority' => 3])
(new ConvertsArrayToFrontMatter)->execute(['priority' => 300])
);
$sidebar = DocumentationSidebarService::get();
$this->assertEquals('first', $sidebar[0]->destination);
Expand Down

0 comments on commit 5854701

Please sign in to comment.