Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #383: Navigation menu titles can't be set in BladeMatter #384

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This serves two purposes:
- for now removed features.

### Fixed
- for any bug fixes.
- Fix [#383](https://github.com/hydephp/develop/issues/383): Navigation menu titles can't be set in BladeMatter

### Security
- in case of vulnerabilities.
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,8 @@ protected function getData(): array

protected function getNavigationMenuTitle(): string
{
if ($this->page instanceof AbstractMarkdownPage) {
if ($this->page->matter('navigation.title') !== null) {
return $this->page->matter('navigation.title');
}

if ($this->page->matter('title') !== null) {
return $this->page->matter('title');
}
if ($this->page->matter('navigation.title') !== null) {
return $this->page->matter('navigation.title');
}

if ($this->page->identifier === 'index') {
Expand All @@ -50,6 +44,10 @@ protected function getNavigationMenuTitle(): string
return config('hyde.navigation.labels.home', 'Home');
}

if ($this->page->matter('title') !== null) {
return $this->page->matter('title');
}

return $this->page->title;
}

Expand Down
26 changes: 26 additions & 0 deletions packages/framework/tests/Unit/Views/NavigationMenuViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Hyde\Framework\Testing\Unit\Views;

use Hyde\Framework\Hyde;
use Hyde\Testing\TestCase;

/**
Expand Down Expand Up @@ -50,4 +51,29 @@ public function test_component_not_contains_404_html_link()
{
$this->assertStringNotContainsString('href="404.html"', $this->render());
}

public function test_navigation_menu_label_can_be_changed_in_front_matter()
{
$this->file('_pages/foo.md', '---
navigation:
title: "My custom title"
---
');
$this->artisan('rebuild _pages/foo.md');
$this->assertStringContainsString('My custom title', file_get_contents(Hyde::path('_site/foo.html')));
Hyde::unlink('_site/foo.html');
}

public function test_navigation_menu_label_can_be_changed_in_blade_matter()
{
$this->file('_pages/foo.blade.php', <<<'BLADE'
@extends('hyde::layouts.app')
@php($navigation = ['title' => 'My custom title'])
BLADE
);

$this->artisan('rebuild _pages/foo.blade.php');
$this->assertStringContainsString('My custom title', file_get_contents(Hyde::path('_site/foo.html')));
Hyde::unlink('_site/foo.html');
}
}