From 25aef907e9cf8851dc66085b688e5ca021410d67 Mon Sep 17 00:00:00 2001 From: wwenrr Date: Wed, 1 Apr 2026 14:28:26 +0000 Subject: [PATCH] fix: avoid crash when jekyll-archives.layouts is not a hash Handle malformed jekyll-archives.layouts config defensively by falling back to the default layout key instead of calling dig on a non-Hash value. Add regression coverage for malformed layouts config to ensure archive generation does not crash. Fixes #181 --- lib/jekyll-archives/archive.rb | 6 ++++-- test/test_jekyll_archives.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-archives/archive.rb b/lib/jekyll-archives/archive.rb index da75b47..34c53a6 100644 --- a/lib/jekyll-archives/archive.rb +++ b/lib/jekyll-archives/archive.rb @@ -47,14 +47,16 @@ def initialize(site, title, type, posts) # # Returns the template String. def template - @config.dig("permalinks", type) + permalinks = @config["permalinks"] + permalinks[type] if permalinks.is_a?(Hash) end # The layout to use for rendering # # Returns the layout as a String def layout - @config.dig("layouts", type) || @config["layout"] + layouts = @config["layouts"] + (layouts[type] if layouts.is_a?(Hash)) || @config["layout"] end # Returns a hash of URL placeholder names (as symbols) mapping to the diff --git a/test/test_jekyll_archives.rb b/test/test_jekyll_archives.rb index 2ac1ea1..a124c97 100644 --- a/test/test_jekyll_archives.rb +++ b/test/test_jekyll_archives.rb @@ -133,6 +133,25 @@ class TestJekyllArchives < Minitest::Test end end + + context "the jekyll-archives plugin with malformed layouts config" do + setup do + @site = fixture_site( + "jekyll-archives" => { + "enabled" => true, + "layouts" => "archive-too", + } + ) + end + + should "fall back to the default layout instead of crashing" do + @site.process + + assert_equal "Test", read_file("/2014/index.html") + assert_equal "Test", read_file("/tag/test-tag/index.html") + end + end + context "the archives" do setup do @site = fixture_site("jekyll-archives" => {