Adjust caching and accessibility

This commit is contained in:
2026-01-24 20:13:43 -06:00
parent 0752f7e3e3
commit ae7961ee07
2 changed files with 25 additions and 9 deletions

View File

@@ -9,9 +9,13 @@
.archive-tree-year { .archive-tree-year {
font-weight: normal; font-weight: normal;
} }
.archive-tree-month-list {
margin: 0;
padding-left: 2em;
}
.archive-tree-month { .archive-tree-month {
margin-left: 2em; margin-left: 0;
padding-left: 0.5em; padding-left: 0;
border-left: 2px solid #ccc; border-left: 2px solid #ccc;
display: block; display: block;
} }

View File

@@ -114,32 +114,44 @@ class ArchiveTreeBlock extends BlockBase {
foreach ($tree as $year => $data) { foreach ($tree as $year => $data) {
$year_url = '/archive-tree/' . $year . '/' . $type_arg; $year_url = '/archive-tree/' . $year . '/' . $type_arg;
$open = $expand ? ' open' : ''; $open = $expand ? ' open' : '';
$output .= '<details' . $open . '><summary class="archive-tree-year">'; $output .= '<details' . $open . ' aria-label="Archive for ' . $year . '"><summary class="archive-tree-year">';
$output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')'; $output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')';
$output .= '</summary>'; $output .= '</summary>';
if (!empty($data['months'])) { if (!empty($data['months'])) {
$output .= '<ul class="archive-tree-month-list">';
foreach ($data['months'] as $month => $month_data) { foreach ($data['months'] as $month => $month_data) {
$month_url = '/archive-tree/' . $year . '/' . $month . '/' . $type_arg; $month_url = '/archive-tree/' . $year . '/' . $month . '/' . $type_arg;
$output .= '<div class="archive-tree-month">'; $output .= '<li class="archive-tree-month">';
$output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $month_data['count'] . ')'; $output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $month_data['count'] . ')';
$output .= '</div>'; $output .= '</li>';
} }
$output .= '</ul>';
} }
$output .= '</details>'; $output .= '</details>';
} }
return [ return [
'#markup' => '<div class="archive-tree-block">' . $output . '</div>', '#markup' => '<div class="archive-tree-block">' . $output . '</div>',
'#allowed_tags' => ['details', 'summary', 'a', 'div'], '#allowed_tags' => ['details', 'summary', 'a', 'div', 'ul', 'li'],
'#attached' => [ '#attached' => [
'library' => [ 'library' => [
'archive_tree/archive_tree', 'archive_tree/archive_tree',
], ],
], ],
'#cache' => [ '#cache' => [
'contexts' => ['user', 'languages'], // Cache per user, language, route, and theme for accuracy.
'tags' => ['node_list'], 'contexts' => [
'max-age' => -1, 'user',
'languages',
'theme',
],
// Invalidate when any node changes or content type config changes.
'tags' => [
'node_list',
'config:node.type',
],
// Cache for 1 hour (3600 seconds) for performance, but not forever.
'max-age' => 3600,
], ],
]; ];
} }