Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Commit

Permalink
Use image if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
LindseyB committed Jun 2, 2015
1 parent 04f3bd5 commit c77a5fd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions blog.rb
Expand Up @@ -60,6 +60,7 @@ def url_base
@date = source.date
@formatted_date = source.formatted_date
@blurb = source.blurb(200)
@image = source.image

haml :post
else
Expand Down
8 changes: 8 additions & 0 deletions post.rb
Expand Up @@ -71,4 +71,12 @@ def blurb(length=20)
blurb = Sanitize.fragment(self.content)[0...(length-3)] + "..."
end
end

def image
doc = Nokogiri::HTML(self.content)
if img = doc.xpath('//img').first
src = img.attr('src')
URI(src).host ? src : "http://rarlindseysmash.com#{src}"
end
end
end
4 changes: 3 additions & 1 deletion views/layout.haml
Expand Up @@ -8,10 +8,12 @@
%head
%meta{:charset=>"utf8"}
%meta{:content=>"width=device-width, initial-scale=1, maximum-scale=1", :name=>"viewport"}
%meta{:name=>"twitter:card", :content=>"summary"}
%meta{:name=>"twitter:card", :content=> @image ? "summary_large_image" : "summary"}
%meta{:name=>"twitter:site", :content=>"@lindeseybieda"}
%meta{:name=>"twitter:title", :content=>title.sub("»", "»")}
%meta{:name=>"twitter:description", :content=>description.strip}
- if @image
%meta{:name=>"twitter:image", :content=>@image}

/[if lt IE 9]
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
Expand Down

0 comments on commit c77a5fd

Please sign in to comment.