Skip to content

Commit 74439f0

Browse files
authored
Merge pull request #522 from hydephp/create-image-file-object
Create image link helper, fix #434
2 parents 90b338a + 9201367 commit 74439f0

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

resources/views/components/post/image.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<figure aria-label="Cover image" itemprop="image" itemscope itemtype="http://schema.org/ImageObject" role="doc-cover">
2-
<img src="{{ $page->image->getSource() }}" alt="{{ $page->image->description ?? '' }}" title="{{ $page->image->title ?? '' }}" itemprop="image" class="mb-0">
2+
<img src="{{ $page->image->getLink($currentPage) }}" alt="{{ $page->image->description ?? '' }}" title="{{ $page->image->title ?? '' }}" itemprop="image" class="mb-0">
33
<figcaption aria-label="Image caption" itemprop="caption">
44
{!! $page->image->getFluentAttribution() !!}
55
</figcaption>

src/Concerns/Internal/FileHelpers.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static function pageLink(string $destination): string
106106
* @see \Tests\Unit\FileHelperRelativeLinkTest
107107
*
108108
* @param string $destination relative to output directory on compiled site
109-
* @param string $current the current URI path relative to the same root
109+
* @param string $current the current URI path relative to the site root
110110
* @return string
111111
*/
112112
public static function relativeLink(string $destination, string $current = ''): string
@@ -121,6 +121,18 @@ public static function relativeLink(string $destination, string $current = ''):
121121
return str_replace('//', '/', $route);
122122
}
123123

124+
/**
125+
* Gets a relative link to the given image stored in the _site/media folder.
126+
*/
127+
public static function image(string $name, string $current = ''): string
128+
{
129+
if (str_starts_with($name, 'http')) {
130+
return $name;
131+
}
132+
133+
return static::relativeLink('media/'.basename($name), $current);
134+
}
135+
124136
/**
125137
* Return a qualified URI path, if SITE_URL is set in .env, else return false.
126138
*

src/Helpers/Image.php

-11
This file was deleted.

src/Models/Image.php

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public function getSource(): ?string
100100
return $this->uri ?? $this->path ?? null;
101101
}
102102

103+
public function getLink(?string $currentPage = ''): string
104+
{
105+
return Hyde::image($this->getSource() ?? '', $currentPage);
106+
}
107+
103108
public function getContentLength(): int
104109
{
105110
return (new FindsContentLengthForImageObject($this))->execute();

0 commit comments

Comments
 (0)