Skip to content

Commit 5854701

Browse files
committed
Add sidebar config offset, fix #307
1 parent 75a5c99 commit 5854701

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Models/DocumentationSidebarItem.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ protected function findPriorityInConfig(string $slug): int
3636
return 500;
3737
}
3838

39-
return array_search($slug, $orderIndexArray); // + 250?
39+
return array_search($slug, $orderIndexArray) + 250;
40+
41+
// Adding 250 makes so that pages with a front matter priority that is lower
42+
// can be shown first. It's lower than the fallback of 500 so that they
43+
// still come first. This is all to make it easier to mix priorities.
4044
}
4145

4246
public function isHidden(): bool

tests/Feature/Services/DocumentationSidebarServiceTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function test_sidebar_item_priority_set_in_config_overrides_front_matter(
132132
$this->assertEquals(25, DocumentationSidebarService::get()->first()->priority);
133133
}
134134

135-
public function test_both_sidebar_priority_setting_methods_can_be_used()
135+
public function test_sidebar_priorities_can_be_set_in_both_front_matter_and_config()
136136
{
137137
Config::set('hyde.documentationPageOrder', [
138138
'first',
@@ -142,7 +142,7 @@ public function test_both_sidebar_priority_setting_methods_can_be_used()
142142
touch(Hyde::path('_docs/first.md'));
143143
touch(Hyde::path('_docs/second.md'));
144144
file_put_contents(Hyde::path('_docs/third.md'),
145-
(new ConvertsArrayToFrontMatter)->execute(['priority' => 3])
145+
(new ConvertsArrayToFrontMatter)->execute(['priority' => 300])
146146
);
147147
$sidebar = DocumentationSidebarService::get();
148148
$this->assertEquals('first', $sidebar[0]->destination);

0 commit comments

Comments
 (0)