refactor: supprime sidebar gauche, fusionne related+similar en 'A lire aussi'

This commit is contained in:
Cedric Abonnel
2026-05-12 22:57:26 +02:00
parent 98c72f721f
commit c83b27624c
4 changed files with 40 additions and 107 deletions
@@ -1,11 +0,0 @@
accès au compte `root`
su - root
ajout de dépots officiels dans le fichier `''
mise à jour globale
apt update
apt upgrade
ajout de la fonction`sudo''
apt install sudo
@@ -6,7 +6,7 @@
"published": true,
"published_at": "2023-02-09 15:18:57",
"created_at": "2023-02-09 15:18:57",
"updated_at": "2023-02-09 15:18:57",
"updated_at": "2026-05-12 22:54:18",
"revisions": [],
"cover": "",
"files_meta": [],
+21 -30
View File
@@ -575,44 +575,19 @@ switch ($action) {
}
}
// Sidebar gauche : autres catégories avec leurs 5 derniers articles
$categorySidebar = [];
foreach ($_allPublished as $a) {
$aCat = trim($a['category'] ?? '');
if ($aCat === '' || $aCat === $articleCat) {
continue;
}
if (in_array($aCat, $privateCats, true) && !isLoggedIn()) {
continue;
}
if (strtotime((string)($a['published_at'] ?? '')) > time() && !isLoggedIn()) {
continue;
}
if (!isset($categorySidebar[$aCat])) {
$categorySidebar[$aCat] = [];
}
if (count($categorySidebar[$aCat]) < 5) {
$categorySidebar[$aCat][] = $a;
}
}
// Articles proches : un search par mot du titre → OR implicite, cumul des scores
$similarArticles = [];
// Articles proches par titre → OR implicite, cumul des scores
require_once BASE_PATH . '/src/SearchEngine.php';
$_simEngine = new SearchEngine();
$_relatedUuids = array_column($relatedArticles, 'uuid');
$_stopWords = ['avec', 'dans', 'pour', 'une', 'les', 'des', 'sur', 'par', 'qui', 'que',
'tout', 'mais', 'donc', 'comment', 'quand', 'plus', 'cette', 'cet', 'ces',
'mon', 'ton', 'son', 'notre', 'votre', 'leur', 'tres', 'bien', 'fait',
'aussi', 'comme', 'plus', 'sans', 'sous', 'entre', 'vers', 'chez'];
'aussi', 'comme', 'sans', 'sous', 'entre', 'vers', 'chez'];
$_simPool = array_values(array_filter(
$_allPublished,
static function (array $a) use ($article, $privateCats, $_relatedUuids): bool {
static function (array $a) use ($article, $privateCats): bool {
if ($a['uuid'] === $article['uuid']) {
return false;
}
if (in_array($a['uuid'], $_relatedUuids, true)) {
return false;
}
if (strtotime((string)($a['published_at'] ?? '')) > time() && !isLoggedIn()) {
return false;
}
@@ -634,11 +609,27 @@ switch ($action) {
}
}
arsort($_scoreMap);
$similarArticles = array_map(
$_similarArticles = array_map(
fn ($uuid) => $_articleMap[$uuid],
array_slice(array_keys($_scoreMap), 0, 5)
);
unset($_simEngine, $_simPool, $_titleWords, $_stopWords, $_scoreMap, $_articleMap, $_relatedUuids);
unset($_simEngine, $_simPool, $_titleWords, $_stopWords, $_scoreMap, $_articleMap);
// "À lire aussi" : similaires en premier, même catégorie pour compléter jusqu'à 5
$alsoReadArticles = $_similarArticles;
if (count($alsoReadArticles) < 5) {
$_used = array_column($alsoReadArticles, 'uuid');
foreach ($relatedArticles as $_ra) {
if (count($alsoReadArticles) >= 5) {
break;
}
if (!in_array($_ra['uuid'], $_used, true)) {
$alsoReadArticles[] = $_ra;
}
}
unset($_used);
}
unset($_similarArticles);
unset($_allPublished);
+14 -61
View File
@@ -30,35 +30,11 @@ if ($files) {
}
$externalLinks = $article['external_links'] ?? [];
$hasLeftSidebar = !empty($categorySidebar ?? []);
?>
<div class="row g-4 align-items-start flex-lg-nowrap">
<?php if ($hasLeftSidebar): ?>
<div class="post-sidebar-col order-2 order-lg-1">
<aside class="left-sidebar">
<?php foreach ($categorySidebar as $catName => $catArticles): ?>
<div class="left-sidebar-section">
<a href="/categorie/<?= rawurlencode($catName) ?>" class="left-sidebar-cat">
<?= htmlspecialchars($catName) ?>
</a>
<ul class="left-sidebar-list">
<?php foreach ($catArticles as $ca): ?>
<li>
<a href="/post/<?= rawurlencode($ca['slug'] ?? '') ?>">
<?= htmlspecialchars($ca['title']) ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</aside>
</div>
<?php endif; ?>
<!-- Colonne principale -->
<div class="col order-1 order-lg-2">
<div class="col">
<div class="card mb-4">
<?php if (!$article['published']): ?>
@@ -235,45 +211,22 @@ $hasSources = (!empty($externalLinks) || !empty($files))
</div>
<?php endif; ?>
<h6 class="related-sidebar-title">Dans la même catégorie</h6>
<?php if (!empty($relatedArticles ?? [])): ?>
<?php foreach ($relatedArticles as $rel):
$relCover = $rel['cover'] ?? '';
$relCat = trim($rel['category'] ?? '');
$relGradient = coverGradient($relCat !== '' ? $relCat : $rel['uuid'], $allCats ?? []);
$relDate = date('d/m/Y', strtotime((string)($rel['published_at'] ?? $rel['created_at'] ?? '')));
<?php if (!empty($alsoReadArticles ?? [])): ?>
<h6 class="related-sidebar-title">À lire aussi</h6>
<?php foreach ($alsoReadArticles as $_also):
$_alsoCover = $_also['cover'] ?? '';
$_alsoCat = trim($_also['category'] ?? '');
$_alsoGradient = coverGradient($_alsoCat !== '' ? $_alsoCat : $_also['uuid'], $allCats ?? []);
$_alsoDate = date('d/m/Y', strtotime((string)($_also['published_at'] ?? $_also['created_at'] ?? '')));
?>
<a href="/post/<?= rawurlencode($rel['slug'] ?? '') ?>" class="related-card">
<div class="related-card-thumb" style="<?= $relCover !== ''
? 'background-image:url(/file?uuid=' . rawurlencode($rel['uuid']) . '&name=' . rawurlencode($relCover) . ');background-size:cover;background-position:center'
: 'background:' . htmlspecialchars($relGradient) ?>">
<a href="/post/<?= rawurlencode($_also['slug'] ?? '') ?>" class="related-card">
<div class="related-card-thumb" style="<?= $_alsoCover !== ''
? 'background-image:url(/file?uuid=' . rawurlencode($_also['uuid']) . '&name=' . rawurlencode($_alsoCover) . ');background-size:cover;background-position:center'
: 'background:' . htmlspecialchars($_alsoGradient) ?>">
</div>
<div class="related-card-body">
<div class="related-card-title"><?= htmlspecialchars($rel['title']) ?></div>
<div class="related-card-date"><?= $relDate ?></div>
</div>
</a>
<?php endforeach; ?>
<?php else: ?>
<p class="text-muted small">Aucun autre article dans cette catégorie.</p>
<?php endif; ?>
<?php if (!empty($similarArticles ?? [])): ?>
<h6 class="related-sidebar-title mt-4">Articles proches</h6>
<?php foreach ($similarArticles as $sim):
$simCover = $sim['cover'] ?? '';
$simCat = trim($sim['category'] ?? '');
$simGradient = coverGradient($simCat !== '' ? $simCat : $sim['uuid'], $allCats ?? []);
$simDate = date('d/m/Y', strtotime((string)($sim['published_at'] ?? $sim['created_at'] ?? '')));
?>
<a href="/post/<?= rawurlencode($sim['slug'] ?? '') ?>" class="related-card">
<div class="related-card-thumb" style="<?= $simCover !== ''
? 'background-image:url(/file?uuid=' . rawurlencode($sim['uuid']) . '&name=' . rawurlencode($simCover) . ');background-size:cover;background-position:center'
: 'background:' . htmlspecialchars($simGradient) ?>">
</div>
<div class="related-card-body">
<div class="related-card-title"><?= htmlspecialchars($sim['title']) ?></div>
<div class="related-card-date"><?= $simDate ?></div>
<div class="related-card-title"><?= htmlspecialchars($_also['title']) ?></div>
<div class="related-card-date"><?= $_alsoDate ?></div>
</div>
</a>
<?php endforeach; ?>