Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/layout.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
9 changes: 7 additions & 2 deletions public/archive/2026.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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]);
Loading