Skip to content

Commit

Permalink
Icon and logo support with simple tests (#412)
Browse files Browse the repository at this point in the history
Merge pull request 412
  • Loading branch information
ChaosKid42 authored Sep 12, 2024
1 parent f321e1c commit f0ccb2f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
16 changes: 16 additions & 0 deletions lib/jekyll-feed/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
<subtitle>{{ site.description | xml_escape }}</subtitle>
{% endif %}

{% if site.feed.icon %}
{% assign feed_icon = site.feed.icon %}
{% unless feed_icon contains "://" %}
{% assign feed_icon = feed_icon | absolute_url %}
{% endunless %}
<icon>{{ feed_icon | xml_escape }}</icon>
{% endif %}

{% if site.feed.logo %}
{% assign feed_logo = site.feed.logo %}
{% unless feed_logo contains "://" %}
{% assign feed_logo = feed_logo | absolute_url %}
{% endunless %}
<logo>{{ feed_logo | xml_escape }}</logo>
{% endif %}

{% if site.author %}
<author>
<name>{{ site.author.name | default: site.author | xml_escape }}</name>
Expand Down
20 changes: 20 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f0ccb2f

Please sign in to comment.