66 lines
2.8 KiB
PHP
66 lines
2.8 KiB
PHP
<?php ob_start(); ?>
|
|
|
|
<div class="search-page">
|
|
|
|
<form class="search-bar mb-5" action="/" method="GET" role="search">
|
|
<input type="hidden" name="action" value="search">
|
|
<div class="input-group">
|
|
<input type="search" class="form-control form-control-lg" name="q"
|
|
value="<?= htmlspecialchars($searchQuery) ?>"
|
|
placeholder="Rechercher…" autofocus autocomplete="off"
|
|
aria-label="Rechercher">
|
|
<button class="btn btn-primary" type="submit">Rechercher</button>
|
|
</div>
|
|
<div class="form-text mt-1">
|
|
Plusieurs mots = recherche ET · Fautes de frappe tolérées · Accents ignorés
|
|
</div>
|
|
</form>
|
|
|
|
<?php if ($searchQuery !== ''): ?>
|
|
|
|
<?php if (empty($searchResults)): ?>
|
|
<p class="text-muted">Aucun résultat pour <strong><?= htmlspecialchars($searchQuery) ?></strong>.</p>
|
|
<?php else: ?>
|
|
<p class="text-muted mb-4">
|
|
<?= count($searchResults) ?> résultat<?= count($searchResults) > 1 ? 's' : '' ?>
|
|
pour <strong><?= htmlspecialchars($searchQuery) ?></strong>
|
|
</p>
|
|
|
|
<div class="search-results">
|
|
<?php foreach ($searchResults as $r):
|
|
$a = $r['article'];
|
|
$postUrl = '/post/' . rawurlencode($a['slug'] ?? '');
|
|
$cat = trim($a['category'] ?? '');
|
|
$date = $a['published_at'] ? date('d/m/Y', strtotime((string)$a['published_at'])) : '';
|
|
?>
|
|
<article class="search-result">
|
|
<div class="search-result-meta">
|
|
<?php if ($cat !== ''): ?>
|
|
<a class="search-result-cat" href="/?cat=<?= rawurlencode($cat) ?>"><?= htmlspecialchars($cat) ?></a>
|
|
<?php endif; ?>
|
|
<?php if ($date !== ''): ?>
|
|
<time class="search-result-date"><?= $date ?></time>
|
|
<?php endif; ?>
|
|
</div>
|
|
<h2 class="search-result-title">
|
|
<a href="<?= htmlspecialchars($postUrl) ?>"><?= htmlspecialchars($a['title'] ?? '') ?></a>
|
|
</h2>
|
|
<?php if ($r['snippet'] !== ''): ?>
|
|
<p class="search-result-snippet"><?= $r['snippet'] ?></p>
|
|
<?php endif; ?>
|
|
</article>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php endif; ?>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
$content = ob_get_clean();
|
|
$title = $searchQuery !== '' ? 'Recherche : ' . $searchQuery : 'Recherche';
|
|
$metaRobots = 'noindex, follow';
|
|
$canonical = rtrim(APP_URL, '/') . '/';
|
|
include __DIR__ . '/layout.php';
|