From f0ccb2f306bf8c8e591c6dacf7fa33f7a27db94c Mon Sep 17 00:00:00 2001 From: ChaosKid42 Date: Thu, 12 Sep 2024 18:28:11 +0200 Subject: [PATCH] Icon and logo support with simple tests (#412) Merge pull request 412 --- README.md | 9 +++++++++ lib/jekyll-feed/feed.xml | 16 ++++++++++++++++ spec/jekyll-feed_spec.rb | 20 ++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/README.md b/README.md index a0f9d1f2..e4f83f6d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,15 @@ The plugin will automatically use any of the following configuration variables, * `description` - A longer description of what your site is about, e.g., "Where I blog about Jekyll and other awesome things" * `url` - The URL to your site, e.g., `https://example.com`. If none is provided, the plugin will try to use `site.github.url`. * `author` - Global author information (see below) +* `feed.icon` - Icon with 1:1 proportions for readers to use for the blog feed (not supported by all readers; often overridden by a favicon or site icon) +* `feed.logo` - Logo with 2:1 proportions for readers to use for the blog feed (not supported by all readers). + For example, both of the preceding can be expressed: + ```yml + feed: + icon: /images/icon.png + logo: /images/logo.png + ``` + ### Already have a feed path? diff --git a/lib/jekyll-feed/feed.xml b/lib/jekyll-feed/feed.xml index 9068836f..dfc0bfff 100644 --- a/lib/jekyll-feed/feed.xml +++ b/lib/jekyll-feed/feed.xml @@ -27,6 +27,22 @@ {{ site.description | xml_escape }} {% endif %} + {% if site.feed.icon %} + {% assign feed_icon = site.feed.icon %} + {% unless feed_icon contains "://" %} + {% assign feed_icon = feed_icon | absolute_url %} + {% endunless %} + {{ feed_icon | xml_escape }} + {% endif %} + + {% if site.feed.logo %} + {% assign feed_logo = site.feed.logo %} + {% unless feed_logo contains "://" %} + {% assign feed_logo = feed_logo | absolute_url %} + {% endunless %} + {{ feed_logo | xml_escape }} + {% endif %} + {% if site.author %} {{ site.author.name | default: site.author | xml_escape }} diff --git a/spec/jekyll-feed_spec.rb b/spec/jekyll-feed_spec.rb index 41514d1f..83d8e6e7 100644 --- a/spec/jekyll-feed_spec.rb +++ b/spec/jekyll-feed_spec.rb @@ -125,6 +125,8 @@ expect(feed.encoding).to eql("UTF-8") expect(feed.lang).to be_nil expect(feed.valid?).to eql(true) + expect(feed.icon).to be_nil + expect(feed.logo).to be_nil end it "outputs the link" do @@ -238,6 +240,24 @@ def to_s expect(feed.title.content).to eql(site_title.encode(xml: :text)) end end + + context "with site.icon set" do + let(:site_icon) { "myicon.png" } + let(:overrides) { { "feed" => { "icon" => site_icon } } } + + it "uses site.icon for the icon" do + expect(feed.icon.content).to eql("http://example.org/" + site_icon) + end + end + + context "with site.logo set" do + let(:site_logo) { "mylogo.png" } + let(:overrides) { { "feed" => { "logo" => site_logo } } } + + it "uses site.logo for the logo" do + expect(feed.logo.content).to eql("http://example.org/" + site_logo) + end + end end context "smartify" do