Skip to content

Commit

Permalink
Add support for post image
Browse files Browse the repository at this point in the history
  • Loading branch information
pathawks committed Mar 21, 2016
1 parent 5a02b11 commit 7caf663
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Additionally, the plugin will use the following values, if present in a post's Y

* `author` - The author of the post, e.g., "Dr. Jekyll". If none is given, feed readers will look to the feed author as defined in `_config.yml`. Like the feed author, this can also be an object.

* `image` - URL of an image that is representative of the post.
**Note:** URL must be relative to the site root, eg: `/images/example.png`

### Meta tags

The plugin exposes a helper tag to expose the appropriate meta tags to support automated discovery of your feed. Simply place `{% feed_meta %}` someplace in your template's `<head>` section, to output the necessary metadata.
Expand Down
4 changes: 4 additions & 0 deletions lib/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
{% if post.excerpt and post.excerpt != empty %}
<summary>{{ post.excerpt | strip_html | replace: '\n', ' ' | strip | xml_escape }}</summary>
{% endif %}

{% if post.image %}
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post.image | prepend: url_base | xml_escape }}" />
{% endif %}
</entry>
{% endunless %}
{% endfor %}
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/_posts/2013-12-12-dec-the-second.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
excerpt: "Foo"
image: "/image.png"
---

# December the twelfth, actually.
4 changes: 4 additions & 0 deletions spec/jekyll-feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
expect(post.summary.content).to eql("Foo")
end

it "includes the item image" do
expect(contents).to include('<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://example.org/image.png" />')
end

it "doesn't include the item's excerpt if blank" do
if Gem::Version.new(Jekyll::VERSION) > Gem::Version.new('3')
post = feed.items.first
Expand Down

0 comments on commit 7caf663

Please sign in to comment.