Skip to content

Commit

Permalink
Use favicon as default link icon if present (Kovah#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Otanga-Otieno committed Sep 16, 2024
1 parent 89d5847 commit 5eaf6e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions app/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Venturecraft\Revisionable\Revision;
use Venturecraft\Revisionable\RevisionableTrait;
Expand Down Expand Up @@ -268,13 +270,29 @@ public function getIcon(string $additionalClasses = ''): string
return "<!-- Icon icon.$icon could not be found! -->";
}

return view('models.links.partials.link-icon', [
if ($this->hasFavicon()) $icon = 'favicon';
return view('models.links.partials.link-icon', [
'icon' => 'icon.' . $icon,
'class' => $additionalClasses . ' fw',
'title' => $title,
'title' => $title,
'faviconUrl' => $this->url . 'favicon.ico'
]);
}

public function hasFavicon()
{
$faviconUrl = $this->url . 'favicon.ico';
try {
$response = Http::head(($faviconUrl));
return $response->successful();
} catch (\Exception $e) {
Log::error('Check for favicon failed: ' . $e->getMessage());
return false;
}

}


/**
* Output a relative time inside a span with real time information
*
Expand Down
1 change: 1 addition & 0 deletions resources/views/components/icon/favicon.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<img src="{{ $attributes['faviconUrl'] }}" class="" height="20px">
2 changes: 1 addition & 1 deletion resources/views/models/links/partials/link-icon.blade.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<x-dynamic-component :component="$icon" class="{{ $class }}" title="{{ $title }}"/>
<x-dynamic-component :component="$icon" :faviconUrl="$faviconUrl" class="{{ $class }}" title="{{ $title }}"/>
<span class="visually-hidden">{{ $title }}</span>

0 comments on commit 5eaf6e4

Please sign in to comment.