diff --git a/include/layout.inc b/include/layout.inc index 33c7655cbc..fa0f2a0348 100644 --- a/include/layout.inc +++ b/include/layout.inc @@ -367,6 +367,21 @@ function news_archive_sidebar(): void } } +// Get Last-Modified timestamp for a year's archive page: +// mtime of file or latest article, whichever is newer +/** @param list> $news */ +function news_archive_last_modified(array $news, string $pageFile): int +{ + $timestamps = array_map(static fn (array $entry): int => strtotime($entry['published']), $news); + + $mtime = filemtime($pageFile); + if ($mtime !== false) { + $timestamps[] = $mtime; + } + + return $timestamps === [] ? time() : max($timestamps); +} + // Print news function print_news($news, $dog, $max = 5, $return = false) { $retval = []; diff --git a/public/archive/2026.php b/public/archive/2026.php index 82d4c513d6..21c87d4366 100644 --- a/public/archive/2026.php +++ b/public/archive/2026.php @@ -5,7 +5,12 @@ $_SERVER['BASE_PAGE'] = 'archive/2026.php'; require_once __DIR__ . '/../../include/prepend.inc'; news_archive_sidebar(); -site_header("News Archive - 2026", ['cache' => true, 'cache_control' => 15 * 60]); +$news = (new NewsHandler())->getNewsByYear(2026); + +site_header("News Archive - 2026", [ + 'cache' => news_archive_last_modified($news, __FILE__), + 'cache_control' => 15 * 60, +]); ?>

News Archive - 2026

@@ -18,5 +23,5 @@ getNewsByYear(2026), null, 500); +print_news($news, null, 500); site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);