Skip to content

Commit

Permalink
Merge pull request #363 from hydephp/code-cleanup
Browse files Browse the repository at this point in the history
Minor code cleanups and fixes
  • Loading branch information
caendesilva authored Aug 7, 2022
2 parents 850f543 + ade1fa5 commit 8ab35d5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 31 deletions.
42 changes: 42 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Convert an array into YAML Front Matter.
*
* Currently does not support nested arrays.
* Currently, does not support nested arrays.
*/
class ConvertsArrayToFrontMatter
{
Expand Down
29 changes: 6 additions & 23 deletions packages/framework/src/Models/Pages/MarkdownPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public function getMetaProperties(): array
*/
protected function parseFrontMatterMetadata(): void
{
if (! empty($this->matter('description'))) {
$this->metadata['description'] = $this->matter('description');
if (! empty($this->description)) {
$this->metadata['description'] = $this->description;
}

if ($this->matter('author') !== null) {
$this->metadata['author'] = $this->getAuthorName($this->matter('author'));
if ($this->author) {
$this->metadata['author'] = $this->author->getName();
}

if ($this->matter('category') !== null) {
$this->metadata['keywords'] = $this->matter('category');
if ($this->category) {
$this->metadata['keywords'] = $this->category;
}
}

Expand All @@ -109,23 +109,6 @@ protected function makeOpenGraphPropertiesForArticle(): void
}
}

/**
* Parse the author name string from front matter with support for both flat and array notation.
*
* @param string|array $author
* @return string
*
* @deprecated v0.58.x-beta (Use author model instead)
*/
protected function getAuthorName(string|array $author): string
{
if (is_string($author)) {
return $author;
}

return $author['name'] ?? $author['username'] ?? 'Guest';
}

protected function setImageMetadata(): void
{
if ($this->image) {
Expand Down
5 changes: 3 additions & 2 deletions packages/framework/src/StaticPageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hyde\Framework\Concerns\InteractsWithDirectories;
use Hyde\Framework\Contracts\AbstractPage;
use Hyde\Framework\Contracts\PageContract;

/**
* Converts a Page Model into a static HTML page.
Expand All @@ -19,10 +20,10 @@ class StaticPageBuilder
/**
* Construct the class.
*
* @param \Hyde\Framework\Contracts\AbstractPage $page the Page to compile into HTML
* @param \Hyde\Framework\Contracts\AbstractPage|PageContract $page the Page to compile into HTML
* @param bool $selfInvoke if set to true the class will invoke when constructed
*/
public function __construct(protected AbstractPage $page, bool $selfInvoke = false)
public function __construct(protected AbstractPage|PageContract $page, bool $selfInvoke = false)
{
if ($selfInvoke) {
$this->__invoke();
Expand Down
6 changes: 2 additions & 4 deletions packages/framework/tests/Unit/ArticleMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,12 @@ public function test_get_author_returns_author_name_when_author_set_to_array_usi
], $page->getMetadata());
}

public function test_get_author_returns_guest_when_author_set_to_array_without_name_or_username()
public function test_no_author_is_set_when_author_set_to_array_without_name_or_username()
{
$page = MarkdownPost::make(matter: [
'author' => [],
]);

$this->assertEquals([
'author' => 'Guest',
], $page->getMetadata());
$this->assertEquals([], $page->getMetadata());
}
}
2 changes: 1 addition & 1 deletion packages/framework/tests/Unit/PageModelParseHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Hyde\Testing\TestCase;

/**
* @see \Hyde\Framework\Concerns\AbstractPage::parse()
* @covers \Hyde\Framework\Contracts\AbstractPage::parse
*/
class PageModelParseHelperTest extends TestCase
{
Expand Down

0 comments on commit 8ab35d5

Please sign in to comment.