File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -367,6 +367,21 @@ function news_archive_sidebar(): void
367367 }
368368}
369369
370+ // Get Last-Modified timestamp for a year's archive page:
371+ // mtime of file or latest article, whichever is newer
372+ /** @param list<array<array-key, mixed>> $news */
373+ function news_archive_last_modified (array $ news , string $ pageFile ): int
374+ {
375+ $ timestamps = array_map (static fn (array $ entry ): int => strtotime ($ entry ['published ' ]), $ news );
376+
377+ $ mtime = filemtime ($ pageFile );
378+ if ($ mtime !== false ) {
379+ $ timestamps [] = $ mtime ;
380+ }
381+
382+ return $ timestamps === [] ? time () : max ($ timestamps );
383+ }
384+
370385// Print news
371386function print_news ($ news , $ dog , $ max = 5 , $ return = false ) {
372387 $ retval = [];
Original file line number Diff line number Diff line change 55$ _SERVER ['BASE_PAGE ' ] = 'archive/2026.php ' ;
66require_once __DIR__ . '/../../include/prepend.inc ' ;
77news_archive_sidebar ();
8- site_header ("News Archive - 2026 " , ['cache ' => true , 'cache_control ' => 15 * 60 ]);
8+ $ news = (new NewsHandler ())->getNewsByYear (2026 );
9+
10+ site_header ("News Archive - 2026 " , [
11+ 'cache ' => news_archive_last_modified ($ news , __FILE__ ),
12+ 'cache_control ' => 15 * 60 ,
13+ ]);
914?>
1015
1116<h1>News Archive - 2026</h1>
1823
1924<?php
2025
21- print_news (( new NewsHandler ())-> getNewsByYear ( 2026 ) , null , 500 );
26+ print_news ($ news , null , 500 );
2227site_footer (['elephpants ' => true , 'sidebar ' => $ SIDEBAR_DATA ]);
You can’t perform that action at this time.
0 commit comments