implement article permalinks and hide search bar conditionally on index.php

This commit is contained in:
hbrain 2026-06-02 07:44:54 +02:00
parent 3abecc729e
commit 9217f874b4

View file

@ -178,10 +178,20 @@ usort($videos, function($a, $b) use ($videoCache) {
return $bd <=> $ad;
});
$rawKeyword = trim((string)($_GET['q'] ?? ''));
$articleId = trim((string)($_GET['id'] ?? ''));
// Backward compatibility with older filter/query formats.
if ($rawKeyword === '') {
if ($articleId !== '') {
$videos = array_values(array_filter($videos, function($v) use ($articleId) {
return pathinfo($v, PATHINFO_FILENAME) === $articleId;
}));
$rawKeyword = '';
$keywordType = 'general';
$keywordValue = '';
} else {
$rawKeyword = trim((string)($_GET['q'] ?? ''));
// Backward compatibility with older filter/query formats.
if ($rawKeyword === '') {
$legacyTitle = trim((string)($_GET['f_title'] ?? ''));
$legacyDate = trim((string)($_GET['f_date'] ?? ''));
$legacyLocation = trim((string)($_GET['f_location'] ?? ''));
@ -194,17 +204,17 @@ if ($rawKeyword === '') {
$legacy = preg_replace('/^\d{8}[_-]/', '', $legacyJob);
$rawKeyword = nice_title($legacy ?: $legacyJob);
}
}
}
$keywordType = 'general';
$keywordValue = $rawKeyword;
if ($rawKeyword !== '' && preg_match('/^\s*(date|location|place)\s*=\s*(.+)\s*$/i', $rawKeyword, $m)) {
$keywordType = 'general';
$keywordValue = $rawKeyword;
if ($rawKeyword !== '' && preg_match('/^\s*(date|location|place)\s*=\s*(.+)\s*$/i', $rawKeyword, $m)) {
$keywordType = lower_text((string)$m[1]);
if ($keywordType === 'place') $keywordType = 'location';
$keywordValue = trim((string)$m[2]);
}
}
$videos = array_values(array_filter($videos, function($v) use ($videoCache, $keywordType, $keywordValue) {
$videos = array_values(array_filter($videos, function($v) use ($videoCache, $keywordType, $keywordValue) {
if ($keywordValue === '') return true;
$name = basename($v);
@ -226,7 +236,8 @@ $videos = array_values(array_filter($videos, function($v) use ($videoCache, $key
}
return ci_contains($title, $keywordValue) || ci_contains($teaser, $keywordValue) || ci_contains($quoteDa, $keywordValue) || ci_contains($description, $keywordValue);
}));
}));
}
$page = max(1, (int)($_GET['page'] ?? 1));
$per = $config['items_per_page'];
@ -321,6 +332,8 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
.filter-summary{color:#A0A4AB;font-size:.9rem;margin:0 0 .8rem}
.video-row-title{font-size:1.35rem;line-height:1.2;color:#F3F4F6}
.video-row-title a{color:inherit;text-decoration:none}
.video-row-title a:hover{text-decoration:underline}
.video-row-head-mobile{display:none}
.video-info .video-row-title{margin:0 0 .35rem}
.video-info .meta{margin:0 0 .45rem}
@ -348,6 +361,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
<?php include __DIR__ . '/_header.php'; ?>
<main>
<section id="videos">
<?php if ($articleId === ''): ?>
<form method="get" class="filter-form">
<div class="filter-input-wrap">
<input name="q" value="<?=h($rawKeyword)?>" placeholder="Search title/teaser/quote_da/description or use date=... / location=..." aria-label="Search articles">
@ -358,6 +372,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
<span class="sr-only">Filter</span>
</button>
</form>
<?php endif; ?>
<p class="filter-summary">
Showing <?=h((string)$total)?> article(s)
@ -369,6 +384,8 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
<div class="video-list">
<?php foreach($slice as $v):
$name = basename($v);
$base = pathinfo($name, PATHINFO_FILENAME);
$permalinkUrl = query_url(['id' => $base]);
$url = $config['public_videos'].'/'.rawurlencode($name);
$m = $videoCache[$name]['metadata'] ?? video_metadata($v);
$posterUrl = video_thumb_public_url($config, $name);
@ -377,7 +394,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
?>
<article class="video-row">
<div class="video-row-head video-row-head-mobile">
<h2 class="video-row-title"><?=h($m['title'])?></h2>
<h2 class="video-row-title"><a href="<?=h($permalinkUrl)?>"><?=h($m['title'])?></a></h2>
<p class="meta">
<span><a href="<?=h($dateFilterUrl)?>"><?=h($m['date'])?></a></span>
<?php if(!empty($m['location'])): ?><span><a href="<?=h($locFilterUrl)?>"><?=h($m['location'])?></a></span><?php endif; ?>
@ -395,7 +412,7 @@ $siteHeaderTitle = $headerTitles[array_rand($headerTitles)];
<?php endif; ?>
</div>
<div class="video-info">
<h2 class="video-row-title video-row-title-desktop"><?=h($m['title'])?></h2>
<h2 class="video-row-title video-row-title-desktop"><a href="<?=h($permalinkUrl)?>"><?=h($m['title'])?></a></h2>
<p class="meta meta-desktop">
<span><a href="<?=h($dateFilterUrl)?>"><?=h($m['date'])?></a></span>
<?php if(!empty($m['location'])): ?><span><a href="<?=h($locFilterUrl)?>"><?=h($m['location'])?></a></span><?php endif; ?>