Skip to content
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 resources/views/components/post/image.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<figure aria-label="Cover image" itemprop="image" itemscope itemtype="http://schema.org/ImageObject" role="doc-cover">
<img src="{{ $page->image->getSource() }}" alt="{{ $page->image->description ?? '' }}" title="{{ $page->image->title ?? '' }}" itemprop="image" class="mb-0">
<img src="{{ $page->image->getLink($currentPage) }}" alt="{{ $page->image->description ?? '' }}" title="{{ $page->image->title ?? '' }}" itemprop="image" class="mb-0">
<figcaption aria-label="Image caption" itemprop="caption">
{!! $page->image->getFluentAttribution() !!}
</figcaption>
Expand Down
14 changes: 13 additions & 1 deletion src/Concerns/Internal/FileHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function pageLink(string $destination): string
* @see \Tests\Unit\FileHelperRelativeLinkTest
*
* @param string $destination relative to output directory on compiled site
* @param string $current the current URI path relative to the same root
* @param string $current the current URI path relative to the site root
* @return string
*/
public static function relativeLink(string $destination, string $current = ''): string
Expand All @@ -121,6 +121,18 @@ public static function relativeLink(string $destination, string $current = ''):
return str_replace('//', '/', $route);
}

/**
* Gets a relative link to the given image stored in the _site/media folder.
*/
public static function image(string $name, string $current = ''): string
{
if (str_starts_with($name, 'http')) {
return $name;
}

return static::relativeLink('media/'.basename($name), $current);
}

/**
* Return a qualified URI path, if SITE_URL is set in .env, else return false.
*
Expand Down
11 changes: 0 additions & 11 deletions src/Helpers/Image.php

This file was deleted.

5 changes: 5 additions & 0 deletions src/Models/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public function getSource(): ?string
return $this->uri ?? $this->path ?? null;
}

public function getLink(?string $currentPage = ''): string
{
return Hyde::image($this->getSource() ?? '', $currentPage);
}

public function getContentLength(): int
{
return (new FindsContentLengthForImageObject($this))->execute();
Expand Down