Skip to content

Commit

Permalink
Merge pull request #381 from hydephp/add-a-default-category-property-…
Browse files Browse the repository at this point in the history
…value-for-documentation-pages

Add a default category property value for documentation pages hydephp/develop@6948a39
  • Loading branch information
github-actions committed Aug 8, 2022
1 parent 0a2269d commit b4d1855
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources/views/components/docs/grouped-sidebar.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ul id="sidebar" role="list">
@foreach ($sidebar->getGroups() as $group)
<li class="sidebar-category mb-4 mt-4 first:mt-0" role="listitem">
<h4 class="sidebar-category-heading text-base font-semibold mb-2 -ml-1">{{ Hyde::makeTitle($group ?? 'Other') }}</h4>
<h4 class="sidebar-category-heading text-base font-semibold mb-2 -ml-1">{{ Hyde::makeTitle($group) }}</h4>
<ul class="sidebar-category-list ml-4" role="list">
@foreach ($sidebar->getItemsInGroup($group) as $item)
<x-hyde::docs.grouped-sidebar-item :item="$item" :active="$item->route->getRouteKey() === $currentRoute->getRouteKey()" />
Expand Down
7 changes: 5 additions & 2 deletions src/Concerns/FrontMatter/Schemas/DocumentationPageSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ trait DocumentationPageSchema
{
/**
* The sidebar category group, if any.
*
* Can be overridden in front matter, or by putting the
* source file in a subdirectory of the same category name.
*/
public ?string $category = null;

/**
* The label for the page shown in the sidebar.
*/
public ?string $label;
public ?string $label = null;

/**
* Hides the page from the sidebar.
Expand Down Expand Up @@ -42,7 +45,7 @@ protected function getDocumentationPageCategory(): ?string

return str_contains($this->identifier, '/')
? Str::before($this->identifier, '/')
: $this->matter('category');
: $this->matter('category', 'other');
}

protected function findPriorityInConfig(): int
Expand Down
4 changes: 1 addition & 3 deletions src/Models/DocumentationSidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public function generate(): static

public function hasGroups(): bool
{
return $this->items->map(function (NavItem $item) {
return $item->getGroup() !== null;
})->contains(true);
return count($this->getGroups()) >= 1 && $this->getGroups() !== [0 => 'other'];
}

public function getGroups(): array
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/Services/DocumentationSidebarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ public function test_has_groups_returns_true_when_there_are_groups()
$this->assertTrue(DocumentationSidebar::create()->hasGroups());
}

public function test_has_groups_returns_true_when_there_are_multiple_groups()
{
$this->makePage('foo', ['category' => 'bar']);
$this->makePage('bar', ['category' => 'baz']);

$this->assertTrue(DocumentationSidebar::create()->hasGroups());
}

public function test_has_groups_returns_true_when_there_are_multiple_groups_mixed_with_defaults()
{
$this->makePage('foo', ['category' => 'bar']);
$this->makePage('bar', ['category' => 'baz']);
$this->makePage('baz');

$this->assertTrue(DocumentationSidebar::create()->hasGroups());
}

public function test_get_groups_returns_empty_array_when_there_are_no_groups()
{
$this->assertEquals([], DocumentationSidebar::create()->getGroups());
Expand Down

0 comments on commit b4d1855

Please sign in to comment.