feat: rétroliens dans la sidebar des articles
This commit is contained in:
@@ -6,11 +6,22 @@
|
||||
"published": true,
|
||||
"published_at": "2026-06-08 07:00",
|
||||
"created_at": "2026-05-12 23:01:34",
|
||||
"updated_at": "2026-05-12 23:01:34",
|
||||
"updated_at": "2026-05-12 23:18:32",
|
||||
"revisions": [],
|
||||
"cover": "",
|
||||
"files_meta": [],
|
||||
"external_links": [],
|
||||
"external_links": [
|
||||
{
|
||||
"url": "https://varlog.a5l.fr/post/post-install",
|
||||
"name": "Premiers pas DevOps : préparer un système Debian fraîchement installé",
|
||||
"added_at": "2026-05-12 23:18:02",
|
||||
"author": "Cédrix",
|
||||
"meta": {
|
||||
"mime": "text/html",
|
||||
"description": "Lorsqu'on vient de provisionner une machine Debian — que ce soit un conteneur LXC, une VM ou un serveur dédié — quelques étapes initiales sont incontourna…"
|
||||
}
|
||||
}
|
||||
],
|
||||
"seo_title": "",
|
||||
"seo_description": "",
|
||||
"og_image": "",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -633,6 +633,8 @@ switch ($action) {
|
||||
|
||||
unset($_allPublished);
|
||||
|
||||
$backlinks = $articles->getBacklinks($article['slug'] ?? '', $article['uuid']);
|
||||
|
||||
include BASE_PATH . '/templates/post_view.php';
|
||||
break;
|
||||
|
||||
|
||||
@@ -884,6 +884,28 @@ class ArticleManager
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne les articles publiés qui contiennent un lien vers /post/<slug>.
|
||||
*/
|
||||
public function getBacklinks(string $slug, string $excludeUuid = ''): array
|
||||
{
|
||||
$pattern = '/post/' . $slug;
|
||||
$result = [];
|
||||
foreach ($this->getAll(publishedOnly: true) as $article) {
|
||||
if ($excludeUuid !== '' && $article['uuid'] === $excludeUuid) {
|
||||
continue;
|
||||
}
|
||||
foreach ($article['external_links'] ?? [] as $link) {
|
||||
$path = parse_url($link['url'] ?? '', PHP_URL_PATH) ?? '';
|
||||
if ($path === $pattern || rtrim($path, '/') === $pattern) {
|
||||
$result[] = $article;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function removeDir(string $dir): void
|
||||
{
|
||||
foreach (scandir($dir) as $entry) {
|
||||
|
||||
@@ -232,6 +232,27 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (!empty($backlinks ?? [])): ?>
|
||||
<h6 class="related-sidebar-title">Rétroliens</h6>
|
||||
<?php foreach ($backlinks as $_bl):
|
||||
$_blCover = $_bl['cover'] ?? '';
|
||||
$_blCat = trim($_bl['category'] ?? '');
|
||||
$_blGradient = coverGradient($_blCat !== '' ? $_blCat : $_bl['uuid'], $allCats ?? []);
|
||||
$_blDate = date('d/m/Y', strtotime((string)($_bl['published_at'] ?? $_bl['created_at'] ?? '')));
|
||||
?>
|
||||
<a href="/post/<?= rawurlencode($_bl['slug'] ?? '') ?>" class="related-card">
|
||||
<div class="related-card-thumb" style="<?= $_blCover !== ''
|
||||
? 'background-image:url(/file?uuid=' . rawurlencode($_bl['uuid']) . '&name=' . rawurlencode($_blCover) . ');background-size:cover;background-position:center'
|
||||
: 'background:' . htmlspecialchars($_blGradient) ?>">
|
||||
</div>
|
||||
<div class="related-card-body">
|
||||
<div class="related-card-title"><?= htmlspecialchars($_bl['title']) ?></div>
|
||||
<div class="related-card-date"><?= $_blDate ?></div>
|
||||
</div>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user