Author: Matt Stauffer (mattstauffer)
Committer: GitHub (web-flow)
Pusher: sy-records
Date: 2026-10-24T13:45:12+08:00
Commit: Fix `Last-Modified` header on archive pages (#2042) · php/web-php@b9464d1 · GitHub
Raw diff: https://github.com/php/web-php/commit/b9464d18b2c3dffed9110cc1ba6fca901e7a9e4e.diff
Fix `Last-Modified` header on archive pages (#2042)
Changed paths:
M include/layout.inc
M public/archive/2026.php
Diff:
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<array<array-key, mixed>> $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,
+]);
?>
<h1>News Archive - 2026</h1>
@@ -18,5 +23,5 @@
<?php
-print_news((new NewsHandler())->getNewsByYear(2026), null, 500);
+print_news($news, null, 500);
site_footer(['elephpants' => true, 'sidebar' => $SIDEBAR_DATA]);