refactor: supprime sidebar gauche, fusionne related+similar en 'A lire aussi'
This commit is contained in:
@@ -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": true,
|
||||||
"published_at": "2023-02-09 15:18:57",
|
"published_at": "2023-02-09 15:18:57",
|
||||||
"created_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": [],
|
"revisions": [],
|
||||||
"cover": "",
|
"cover": "",
|
||||||
"files_meta": [],
|
"files_meta": [],
|
||||||
|
|||||||
+25
-34
@@ -575,44 +575,19 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sidebar gauche : autres catégories avec leurs 5 derniers articles
|
// Articles proches par titre → OR implicite, cumul des scores
|
||||||
$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 = [];
|
|
||||||
require_once BASE_PATH . '/src/SearchEngine.php';
|
require_once BASE_PATH . '/src/SearchEngine.php';
|
||||||
$_simEngine = new SearchEngine();
|
$_simEngine = new SearchEngine();
|
||||||
$_relatedUuids = array_column($relatedArticles, 'uuid');
|
$_stopWords = ['avec', 'dans', 'pour', 'une', 'les', 'des', 'sur', 'par', 'qui', 'que',
|
||||||
$_stopWords = ['avec', 'dans', 'pour', 'une', 'les', 'des', 'sur', 'par', 'qui', 'que',
|
'tout', 'mais', 'donc', 'comment', 'quand', 'plus', 'cette', 'cet', 'ces',
|
||||||
'tout', 'mais', 'donc', 'comment', 'quand', 'plus', 'cette', 'cet', 'ces',
|
'mon', 'ton', 'son', 'notre', 'votre', 'leur', 'tres', 'bien', 'fait',
|
||||||
'mon', 'ton', 'son', 'notre', 'votre', 'leur', 'tres', 'bien', 'fait',
|
'aussi', 'comme', 'sans', 'sous', 'entre', 'vers', 'chez'];
|
||||||
'aussi', 'comme', 'plus', 'sans', 'sous', 'entre', 'vers', 'chez'];
|
|
||||||
$_simPool = array_values(array_filter(
|
$_simPool = array_values(array_filter(
|
||||||
$_allPublished,
|
$_allPublished,
|
||||||
static function (array $a) use ($article, $privateCats, $_relatedUuids): bool {
|
static function (array $a) use ($article, $privateCats): bool {
|
||||||
if ($a['uuid'] === $article['uuid']) {
|
if ($a['uuid'] === $article['uuid']) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (in_array($a['uuid'], $_relatedUuids, true)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (strtotime((string)($a['published_at'] ?? '')) > time() && !isLoggedIn()) {
|
if (strtotime((string)($a['published_at'] ?? '')) > time() && !isLoggedIn()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -634,11 +609,27 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
arsort($_scoreMap);
|
arsort($_scoreMap);
|
||||||
$similarArticles = array_map(
|
$_similarArticles = array_map(
|
||||||
fn ($uuid) => $_articleMap[$uuid],
|
fn ($uuid) => $_articleMap[$uuid],
|
||||||
array_slice(array_keys($_scoreMap), 0, 5)
|
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);
|
unset($_allPublished);
|
||||||
|
|
||||||
|
|||||||
+14
-61
@@ -30,35 +30,11 @@ if ($files) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$externalLinks = $article['external_links'] ?? [];
|
$externalLinks = $article['external_links'] ?? [];
|
||||||
$hasLeftSidebar = !empty($categorySidebar ?? []);
|
|
||||||
?>
|
?>
|
||||||
<div class="row g-4 align-items-start flex-lg-nowrap">
|
<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 -->
|
<!-- Colonne principale -->
|
||||||
<div class="col order-1 order-lg-2">
|
<div class="col">
|
||||||
|
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<?php if (!$article['published']): ?>
|
<?php if (!$article['published']): ?>
|
||||||
@@ -235,45 +211,22 @@ $hasSources = (!empty($externalLinks) || !empty($files))
|
|||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<h6 class="related-sidebar-title">Dans la même catégorie</h6>
|
<?php if (!empty($alsoReadArticles ?? [])): ?>
|
||||||
<?php if (!empty($relatedArticles ?? [])): ?>
|
<h6 class="related-sidebar-title">À lire aussi</h6>
|
||||||
<?php foreach ($relatedArticles as $rel):
|
<?php foreach ($alsoReadArticles as $_also):
|
||||||
$relCover = $rel['cover'] ?? '';
|
$_alsoCover = $_also['cover'] ?? '';
|
||||||
$relCat = trim($rel['category'] ?? '');
|
$_alsoCat = trim($_also['category'] ?? '');
|
||||||
$relGradient = coverGradient($relCat !== '' ? $relCat : $rel['uuid'], $allCats ?? []);
|
$_alsoGradient = coverGradient($_alsoCat !== '' ? $_alsoCat : $_also['uuid'], $allCats ?? []);
|
||||||
$relDate = date('d/m/Y', strtotime((string)($rel['published_at'] ?? $rel['created_at'] ?? '')));
|
$_alsoDate = date('d/m/Y', strtotime((string)($_also['published_at'] ?? $_also['created_at'] ?? '')));
|
||||||
?>
|
?>
|
||||||
<a href="/post/<?= rawurlencode($rel['slug'] ?? '') ?>" class="related-card">
|
<a href="/post/<?= rawurlencode($_also['slug'] ?? '') ?>" class="related-card">
|
||||||
<div class="related-card-thumb" style="<?= $relCover !== ''
|
<div class="related-card-thumb" style="<?= $_alsoCover !== ''
|
||||||
? 'background-image:url(/file?uuid=' . rawurlencode($rel['uuid']) . '&name=' . rawurlencode($relCover) . ');background-size:cover;background-position:center'
|
? 'background-image:url(/file?uuid=' . rawurlencode($_also['uuid']) . '&name=' . rawurlencode($_alsoCover) . ');background-size:cover;background-position:center'
|
||||||
: 'background:' . htmlspecialchars($relGradient) ?>">
|
: 'background:' . htmlspecialchars($_alsoGradient) ?>">
|
||||||
</div>
|
</div>
|
||||||
<div class="related-card-body">
|
<div class="related-card-body">
|
||||||
<div class="related-card-title"><?= htmlspecialchars($rel['title']) ?></div>
|
<div class="related-card-title"><?= htmlspecialchars($_also['title']) ?></div>
|
||||||
<div class="related-card-date"><?= $relDate ?></div>
|
<div class="related-card-date"><?= $_alsoDate ?></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>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user