Derive meta-description hours from Hours & Visit data instead of hardcoding
The <meta description>, og:description, and twitter:description tags all had "Open Thursday through Saturday, 4–10pm" typed in by hand, so editing hours in the admin panel silently left the page's search/social preview copy wrong. Added hours_meta_summary() to inc/hours.php, built from the same group_hours_into_ranges() grouping the Hours & Visit card and footer already use, so all three now read the live pub_hours data and stay in sync with whatever's set under Hours & Visit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bbe84e8614
commit
e0904b368c
2 files changed
+80
-3
No files matched your search
@@ -263,6 +263,82 @@ function day_abbr_range(array $days, string $dash = ' – '): string {
|
||||
return HOURS_DAY_ABBR[$days[0]] . $dash . HOURS_DAY_ABBR[end($days)];
|
||||
}
|
||||
|
||||
/**
|
||||
* "4pm" / "4:30pm" — tight, lowercase, no leading-zero-minute clutter.
|
||||
* Used only by format_time_range_compact() below for the meta-description
|
||||
* summary's condensed style; the site's on-page hours use format_time_12h
|
||||
* instead, which keeps a space and uppercase AM/PM.
|
||||
*/
|
||||
function format_hour_compact(int $hour, int $minute): string {
|
||||
$period = $hour >= 12 ? 'pm' : 'am';
|
||||
$hour12 = $hour % 12;
|
||||
if ($hour12 === 0) {
|
||||
$hour12 = 12;
|
||||
}
|
||||
if ($minute === 0) {
|
||||
return "{$hour12}{$period}";
|
||||
}
|
||||
return sprintf('%d:%02d%s', $hour12, $minute, $period);
|
||||
}
|
||||
|
||||
/**
|
||||
* "4–10pm" (or "11am–2pm" when the two ends straddle noon) — same single
|
||||
* trailing-meridiem rule as format_time_range(), but compact/lowercase to
|
||||
* match the site's existing meta-description copy style.
|
||||
*/
|
||||
function format_time_range_compact(string $openTime, string $closeTime): string {
|
||||
[$openHour, $openMin] = array_map('intval', explode(':', $openTime));
|
||||
[$closeHour, $closeMin] = array_map('intval', explode(':', $closeTime));
|
||||
$openPeriod = $openHour >= 12 ? 'pm' : 'am';
|
||||
$closePeriod = $closeHour >= 12 ? 'pm' : 'am';
|
||||
|
||||
$openLabel = format_hour_compact($openHour, $openMin);
|
||||
$closeLabel = format_hour_compact($closeHour, $closeMin);
|
||||
|
||||
if ($openPeriod === $closePeriod) {
|
||||
$openLabel = substr($openLabel, 0, -strlen($openPeriod));
|
||||
}
|
||||
|
||||
return "{$openLabel}–{$closeLabel}";
|
||||
}
|
||||
|
||||
/**
|
||||
* "Thursday" for a single day, "Thursday through Saturday" for a run —
|
||||
* the full-name equivalent of day_abbr_range(), for prose summaries.
|
||||
*/
|
||||
function day_name_range(array $days): string {
|
||||
if (count($days) === 1) {
|
||||
return HOURS_DAY_NAMES[$days[0]];
|
||||
}
|
||||
return HOURS_DAY_NAMES[$days[0]] . ' through ' . HOURS_DAY_NAMES[end($days)];
|
||||
}
|
||||
|
||||
/**
|
||||
* "Open Thursday through Saturday, 4–10pm." — the one-line summary used in
|
||||
* <meta name="description">, og:description and twitter:description, built
|
||||
* from the same day groupings as the rest of this file so the blurb search
|
||||
* engines and social previews show always matches whatever's actually set
|
||||
* in Hours & Visit / the admin hours page, instead of hand-typed copy that
|
||||
* can silently drift out of date.
|
||||
*/
|
||||
function hours_meta_summary(array $hoursByDay): string {
|
||||
$openGroups = array_values(array_filter(
|
||||
group_hours_into_ranges($hoursByDay),
|
||||
fn(array $group): bool => $group['is_open']
|
||||
));
|
||||
|
||||
if (empty($openGroups)) {
|
||||
return 'Check our Facebook page for current hours.';
|
||||
}
|
||||
|
||||
$parts = [];
|
||||
foreach ($openGroups as $group) {
|
||||
$parts[] = day_name_range($group['days']) . ', ' . format_time_range_compact($group['data']['open_time'], $group['data']['close_time']);
|
||||
}
|
||||
|
||||
return 'Open ' . implode('; ', $parts) . '.';
|
||||
}
|
||||
|
||||
/**
|
||||
* "Kitchen closes at 9 PM" — or, if open days don't all share one kitchen
|
||||
* closing time, one clause per distinct time naming which days it applies
|
||||
|
||||
@@ -8,6 +8,7 @@ $googleReviews = fritz_google_reviews();
|
||||
$activeAnnouncements = get_active_announcements();
|
||||
$hoursByDay = get_all_hours();
|
||||
$siteUrl = rtrim(SITE_URL, '/');
|
||||
$hoursSummary = hours_meta_summary($hoursByDay);
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
@@ -21,7 +22,7 @@ $siteUrl = rtrim(SITE_URL, '/');
|
||||
<link rel="stylesheet" href="styles.css<?= asset_version('styles.css') ?>">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,400;1,9..144,500&family=Karla:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap" rel="stylesheet">
|
||||
|
||||
<meta name="description" content="The Old Fitz Public House — a traditional Irish pub in Marion, Indiana. Open Thursday through Saturday, 4–10pm. Family friendly, no reservations.">
|
||||
<meta name="description" content="The Old Fitz Public House — a traditional Irish pub in Marion, Indiana. <?= htmlspecialchars($hoursSummary) ?> Family friendly, no reservations.">
|
||||
<link rel="canonical" href="https://theoldfitz.daviddyer.me">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
|
||||
@@ -29,7 +30,7 @@ $siteUrl = rtrim(SITE_URL, '/');
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:site_name" content="The Old Fitz Public House">
|
||||
<meta property="og:title" content="The Old Fitz Public House | Traditional Irish Pub in Marion, Indiana">
|
||||
<meta property="og:description" content="A traditional Irish pub in Marion, Indiana. Open Thursday through Saturday, 4–10pm. Family friendly, no reservations.">
|
||||
<meta property="og:description" content="A traditional Irish pub in Marion, Indiana. <?= htmlspecialchars($hoursSummary) ?> Family friendly, no reservations.">
|
||||
<meta property="og:url" content="<?= $siteUrl ?>/">
|
||||
<meta property="og:image" content="<?= $siteUrl ?>/assets/og-image.png">
|
||||
<meta property="og:image:width" content="1200">
|
||||
@@ -39,7 +40,7 @@ $siteUrl = rtrim(SITE_URL, '/');
|
||||
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="The Old Fitz Public House | Traditional Irish Pub in Marion, Indiana">
|
||||
<meta name="twitter:description" content="A traditional Irish pub in Marion, Indiana. Open Thursday through Saturday, 4–10pm. Family friendly, no reservations.">
|
||||
<meta name="twitter:description" content="A traditional Irish pub in Marion, Indiana. <?= htmlspecialchars($hoursSummary) ?> Family friendly, no reservations.">
|
||||
<meta name="twitter:image" content="<?= $siteUrl ?>/assets/og-image.png">
|
||||
</head>
|
||||
|
||||
|
||||
Reference in new issue
Block a user