Normalize URLs for server status matching and update error page titles

This commit is contained in:
Fabian Schieder 2026-03-01 14:24:00 +01:00
parent 9020a7f7a3
commit f6fd033c21
3 changed files with 46 additions and 6 deletions

View File

@ -6,7 +6,7 @@ http_response_code(404);
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Seite nicht gefunden · Fabian Schieder</title>
<title>Seite nicht gefunden · Fabian Schieder</title>
<link rel="stylesheet" href="/style.css">
<style>
body {

View File

@ -6,7 +6,7 @@ http_response_code(503);
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Seite nicht gefunden · Fabian Schieder</title>
<title>Dienst nicht verfügbar · Fabian Schieder</title>
<link rel="stylesheet" href="/style.css">
<style>
body {

View File

@ -5,6 +5,45 @@
* - $items (array)
* - $serverStatusByUrl (array)
*/
// Hilfsfunktion: URLs für Status-Matching normalisieren (z.B. /nextcloud vs /nextcloud/)
$__normalize_status_url = static function (string $url): string {
$u = trim($url);
if ($u === '') return $u;
// Nur Trailing Slash entfernen (aber nicht bei "https://host/")
$parts = parse_url($u);
if (!is_array($parts) || empty($parts['scheme']) || empty($parts['host'])) {
return rtrim($u, '/');
}
$path = $parts['path'] ?? '';
if (is_string($path) && $path !== '' && $path !== '/') {
$parts['path'] = rtrim($path, '/');
if ($parts['path'] === '') {
$parts['path'] = '/';
}
}
$normalized = strtolower((string)$parts['scheme']) . '://' . (string)$parts['host'];
if (!empty($parts['port'])) {
$normalized .= ':' . (string)$parts['port'];
}
$normalized .= (string)($parts['path'] ?? '');
if (!empty($parts['query'])) {
$normalized .= '?' . (string)$parts['query'];
}
return $normalized;
};
// Normalisierte Map bauen (damit das Matching tolerant ist)
$__serverStatusByUrlNormalized = [];
foreach ($serverStatusByUrl as $__u => $__svc) {
if (is_string($__u)) {
$__serverStatusByUrlNormalized[$__normalize_status_url($__u)] = $__svc;
}
}
?>
<section>
<h2 class="category-title">
@ -19,20 +58,21 @@
$statusKey = null;
// 1) Externe absolute URL direkt matchen
if (!empty($project['url']) && isset($serverStatusByUrl[$project['url']])) {
$statusKey = $project['url'];
if (!empty($project['url']) && isset($__serverStatusByUrlNormalized[$__normalize_status_url((string)$project['url'])])) {
$statusKey = $__normalize_status_url((string)$project['url']);
}
// 2) Interne Pfade (/git, /nextcloud) auf Domain mappen
if ($statusKey === null && !empty($project['url']) && is_string($project['url']) && substr($project['url'], 0, 1) === '/') {
$statusKeyCandidate = 'https://fabianschieder.com' . $project['url'];
if (isset($serverStatusByUrl[$statusKeyCandidate])) {
$statusKeyCandidate = $__normalize_status_url($statusKeyCandidate);
if (isset($__serverStatusByUrlNormalized[$statusKeyCandidate])) {
$statusKey = $statusKeyCandidate;
}
}
if ($statusKey !== null) {
$status = $serverStatusByUrl[$statusKey];
$status = $__serverStatusByUrlNormalized[$statusKey];
}
$state = $status ? (string)($status['state'] ?? 'unknown') : null;