diff --git a/lib/jekyll-github-metadata/value.rb b/lib/jekyll-github-metadata/value.rb index 49e16ae..7082534 100644 --- a/lib/jekyll-github-metadata/value.rb +++ b/lib/jekyll-github-metadata/value.rb @@ -34,7 +34,7 @@ def render def to_liquid case render - when nil, true, false, Hash, String, Numeric, Array + when nil, true, false, Hash, String, Numeric, Array, Time value else to_json diff --git a/spec/value_spec.rb b/spec/value_spec.rb index 86b3a10..a9c1cf7 100644 --- a/spec/value_spec.rb +++ b/spec/value_spec.rb @@ -11,6 +11,7 @@ let(:nil_value_without_key) { described_class.new(nil) } let(:nil_value_with_key) { described_class.new("my_key", nil) } let(:key_and_value) { described_class.new("my_key2", proc { "leonard told me" }) } + let(:time_value) { described_class.new(Time.utc(2025, 1, 29, 12, 0, 0)) } it "takes in a value and stores it" do v = described_class.new("some_value") @@ -55,6 +56,16 @@ expect(hash_value.render).to eql("hello" => "world") end + it "does not modify a time value" do + expect(time_value.render).to be_a(Time) + expect(time_value.render).to eql(Time.utc(2025, 1, 29, 12, 0, 0)) + end + + it "returns Time objects directly from to_liquid for date filter compatibility" do + expect(time_value.to_liquid).to be_a(Time) + expect(time_value.to_liquid).to eql(Time.utc(2025, 1, 29, 12, 0, 0)) + end + it "accepts a nil value with no key" do expect(nil_value_without_key.key).to eql("{anonymous}") expect(nil_value_without_key.render).to be_nil