1
0

Improved links testing and displaying

This commit is contained in:
Richard Dern 2024-04-24 13:55:08 +02:00
parent b8d39081c6
commit 78fdaa6485
6 changed files with 40 additions and 9 deletions

View File

@ -29,7 +29,7 @@ class Link
private string $title;
public function __construct(protected string $url, protected ?string $innerHtml, protected ?Bundle $bundle = null)
public function __construct(protected string $url, protected ?string $innerHtml = null, protected ?Bundle $bundle = null)
{
}
@ -141,7 +141,7 @@ public function title(): string
public function toArray(): array
{
if ($this->bundle !== null) {
$existingData = $this->bundle->metadata('links')->get($this->url, []);
$existingData = $this->bundle->metadata('links')->get($this->url, [], false);
if (!empty($existingData['checked']) && Carbon::parse($existingData['checked'])->gt(now()->subMonth())) {
return $existingData;
@ -191,7 +191,7 @@ public function toHtmlElement(): HtmlElement
'rel' => $data['rel'],
'title' => $data['title'],
'class' => $data['classes'],
], $this->innerHtml);
], $this->innerHtml ?? $this->url);
}
/**

View File

@ -117,9 +117,13 @@ public function merge(array $array)
* @param mixed $default The default value to return if the key does not exist.
* @return mixed The value of the specified key, or the default value.
*/
public function get($key, $default = null)
public function get($key, $default = null, bool $respectDots = true)
{
return data_get($this->content, $key, $default);
if ($respectDots) {
return data_get($this->content, $key, $default);
} else {
return $this->content[$key] ?? $default;
}
}
/**

View File

@ -4,6 +4,7 @@
use App\Classes\AttachmentsManager;
use App\Classes\Bundle;
use App\Classes\Link;
use App\Services\BundleRenderers\Contracts\RendersBundle;
use Carbon\Carbon;
use Exception;
@ -93,6 +94,15 @@ protected function shareCommonDataWithView(): void
data_set($this->viewData, 'siteTitle', $this->bundle->getSiteTitle());
data_set($this->viewData, 'articleTitle', $this->bundle->getArticleTitle());
data_set($this->viewData, 'bundle', $this->bundle);
if (!empty($this->bundle->metadata('metadata')->get('links.Page originale'))) {
$url = $this->bundle->metadata('metadata')->get('links.Page originale')[0];
$link = (new Link($url, null, $this->bundle))->toArray();
$link['url'] = $url;
data_set($this->viewData, 'mainLink', $link);
}
}
protected function handlePagination()

View File

@ -13,6 +13,7 @@ .article-list {
color: #6c7a89;
box-shadow: 0 1px 1rem #000;
background: #01010c radial-gradient(at bottom center, #00101f, #000614, #01010c) no-repeat;
position: relative;
.article-card {
font-size: 1rem;

View File

@ -3,14 +3,21 @@
@if (!empty($cover))
{!! $cover !!}
@endif
@if(!empty($mainLink) && $mainLink['isDead'])
<div class="ribbon dead" title="{{ $mainLink['reason'] }}">
Lien mort depuis le {{ Carbon\Carbon::parse($mainLink['checked'])->format('d/m/Y') }}
</div>
@endif
<h2>{!! $bundle->getArticleTitle() !!}</h2>
<section class="article-card-body">
@if (!empty($date))
@if (!empty($date))
<p><time datetime="{{ $date->toIso8601String() }}">{{ $date->isoFormat('LL') }}</time></p>
@endif
@if (!empty($section))
@endif
@if (!empty($section))
<p>{!! $section->getArticleTitle() !!}</p>
@endif
@endif
</section>
</article>
</a>

View File

@ -6,6 +6,15 @@
@if (empty($bundle->metadata()->get('hide_title')))
<h1>{{ $articleTitle }}</h1>
@endif
@if(!empty($mainLink))
<p><a
href="{!! $mainLink['finalUrl'] !!}"
rel="{!! $mainLink['rel'] !!}"
class="{!! $mainLink['classes'] !!}"
title="{!! $mainLink['title'] !!}">{!! $mainLink['url'] !!}</a></p>
@endif
@if (!empty($date))
<time datetime="{{ $date->toIso8601String() }}">{{ $date->isoFormat('LL') }}</time>
@endif