From e0904b368caa55e22f8280c9e97fa88d7fc601e9 Mon Sep 17 00:00:00 2001 From: David Dyer Date: Wed, 2 Sep 2026 10:27:42 -0400 Subject: [PATCH] Derive meta-description hours from Hours & Visit data instead of hardcoding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The , 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 --- inc/hours.php | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 7 +++-- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/inc/hours.php b/inc/hours.php index 1560915..7bfbadb 100644 --- a/inc/hours.php +++ b/inc/hours.php @@ -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 + * , 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 diff --git a/index.php b/index.php index 8551a0a..6a7cf68 100644 --- a/index.php +++ b/index.php @@ -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); ?> @@ -21,7 +22,7 @@ $siteUrl = rtrim(SITE_URL, '/'); - + @@ -29,7 +30,7 @@ $siteUrl = rtrim(SITE_URL, '/'); - + @@ -39,7 +40,7 @@ $siteUrl = rtrim(SITE_URL, '/'); - +