From ae7961ee07fc3863bf93757521ddec2aa6bdaef9 Mon Sep 17 00:00:00 2001 From: Aaron Axvig Date: Sat, 24 Jan 2026 20:13:43 -0600 Subject: [PATCH] Adjust caching and accessibility --- css/archive_tree.css | 8 ++++++-- src/Plugin/Block/ArchiveTreeBlock.php | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/css/archive_tree.css b/css/archive_tree.css index a21d37c..19f2b81 100644 --- a/css/archive_tree.css +++ b/css/archive_tree.css @@ -9,9 +9,13 @@ .archive-tree-year { font-weight: normal; } +.archive-tree-month-list { + margin: 0; + padding-left: 2em; +} .archive-tree-month { - margin-left: 2em; - padding-left: 0.5em; + margin-left: 0; + padding-left: 0; border-left: 2px solid #ccc; display: block; } diff --git a/src/Plugin/Block/ArchiveTreeBlock.php b/src/Plugin/Block/ArchiveTreeBlock.php index 5ad2ed0..ffe219b 100644 --- a/src/Plugin/Block/ArchiveTreeBlock.php +++ b/src/Plugin/Block/ArchiveTreeBlock.php @@ -114,32 +114,44 @@ class ArchiveTreeBlock extends BlockBase { foreach ($tree as $year => $data) { $year_url = '/archive-tree/' . $year . '/' . $type_arg; $open = $expand ? ' open' : ''; - $output .= ''; + $output .= ''; $output .= '' . $year . ' (' . $data['count'] . ')'; $output .= ''; if (!empty($data['months'])) { + $output .= '
    '; foreach ($data['months'] as $month => $month_data) { $month_url = '/archive-tree/' . $year . '/' . $month . '/' . $type_arg; - $output .= '
    '; + $output .= '
  • '; $output .= '' . $month . ' (' . $month_data['count'] . ')'; - $output .= '
  • '; + $output .= ''; } + $output .= '
'; } $output .= ''; } return [ '#markup' => '
' . $output . '
', - '#allowed_tags' => ['details', 'summary', 'a', 'div'], + '#allowed_tags' => ['details', 'summary', 'a', 'div', 'ul', 'li'], '#attached' => [ 'library' => [ 'archive_tree/archive_tree', ], ], '#cache' => [ - 'contexts' => ['user', 'languages'], - 'tags' => ['node_list'], - 'max-age' => -1, + // Cache per user, language, route, and theme for accuracy. + 'contexts' => [ + '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, ], ]; }