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

Breaking: Rename "credit" front matter and class property to "attributionUrl" for blog post images #613

Merged
merged 2 commits into from
Oct 28, 2022
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 docs/creating-content/blog-posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ image:
copyright: "Copyright (c) 2022"
license: "CC-BY-SA-4.0"
licenseUrl: https://example.com/license/
credit: https://photographer.example.com/
attributionUrl: https://photographer.example.com/
author: "John Doe"
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* 'license' => '?string',
* 'licenseUrl' => '?string',
* 'author' => '?string',
* 'credit' => '?string'
* 'attributionUrl' => '?string'
* ];
*
* @see \Hyde\Framework\Testing\Feature\ImageModelTest
Expand Down Expand Up @@ -96,9 +96,11 @@ class FeaturedImage implements FeaturedImageSchema, Stringable
* Link to the image author/source (for attribution/credit).
* When added, the rendered $author's name will link to this URL.
*
* @note This was previously called "credit" but was renamed to "attributionUrl" for clarity.
*
* @example "https://unsplash.com/photos/example".
*/
public ?string $credit = null;
public ?string $attributionUrl = null;

public function __construct(array $data = [])
{
Expand Down Expand Up @@ -225,9 +227,9 @@ public function getLicenseString(): string|null
return null;
}

protected function getCreditedAuthorLink(): string
protected function getAuthorLink(): string
{
return '<a href="'.e($this->credit).'" rel="author noopener nofollow" itemprop="url">'.$this->getAuthorSpan().'</a>';
return '<a href="'.e($this->attributionUrl).'" rel="author noopener nofollow" itemprop="url">'.$this->getAuthorSpan().'</a>';
}

protected function getAuthorSpan(): string
Expand All @@ -237,8 +239,8 @@ protected function getAuthorSpan(): string

protected function getAuthorElement(): string
{
return isset($this->credit)
? $this->getCreditedAuthorLink()
return isset($this->attributionUrl)
? $this->getAuthorLink()
: $this->getAuthorSpan();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
interface FeaturedImageSchema
{
public const FEATURED_IMAGE_SCHEMA = [
'path' => 'string',
'url' => 'string',
'description' => 'string',
'title' => 'string',
'copyright' => 'string',
'license' => 'string',
'licenseUrl' => 'string',
'author' => 'string',
'credit' => 'string',
'path' => 'string',
'url' => 'string',
'description' => 'string',
'title' => 'string',
'copyright' => 'string',
'license' => 'string',
'licenseUrl' => 'string',
'author' => 'string',
'attributionUrl' => 'string',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test_get_image_author_attribution_string_method()
{
$image = new FeaturedImage([
'author' => 'John Doe',
'credit' => 'https://example.com/',
'attributionUrl' => 'https://example.com/',
]);
$string = $image->getImageAuthorAttributionString();
$this->assertStringContainsString('itemprop="creator"', $string);
Expand Down
18 changes: 9 additions & 9 deletions packages/framework/tests/Unit/SchemaContractsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public function testSchemasAreNotAccidentallyChanged()
], BlogPostSchema::AUTHOR_SCHEMA);

$this->assertEquals([
'path' => 'string',
'url' => 'string',
'description' => 'string',
'title' => 'string',
'copyright' => 'string',
'license' => 'string',
'licenseUrl' => 'string',
'author' => 'string',
'credit' => 'string',
'path' => 'string',
'url' => 'string',
'description' => 'string',
'title' => 'string',
'copyright' => 'string',
'license' => 'string',
'licenseUrl' => 'string',
'author' => 'string',
'attributionUrl' => 'string',
], BlogPostSchema::FEATURED_IMAGE_SCHEMA);

$this->assertEquals([
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/_posts/typography-front-matter.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ image:
license: "the Unsplash License"
licenseUrl: "https://unsplash.com/license"
author: "Blake"
credit: "https://unsplash.com/photos/GFrBMipOd_E"
attributionUrl: "https://unsplash.com/photos/GFrBMipOd_E"
---

## Write something awesome.
Expand Down