Created
July 18, 2012 07:21
-
-
Save 1gor/3134795 to your computer and use it in GitHub Desktop.
Nanoc helper to display blog post summary and a link to the full post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module My | |
module Helpers | |
# Nanoc helper to display blog post summary and a link to the full post. | |
# Used inside <% sorted_articles.each do |item| %>...<% end %> block etc. | |
# | |
# @example Put the following in your layout: | |
# | |
# <%= article_summary(item,'Read the full article>>') %> | |
# | |
# To customize the link text you can add 'read_more' attribute to your | |
# item metadata or pass the string to the helper, as above. | |
# | |
# Add <!--MORE--> separator somewhere in your item to split it. Otherwise | |
# the full article text is displayed. | |
# | |
# @param [String] item The blog post | |
# | |
# @param [String] read_more_text The 'Read more...' text | |
# | |
# @param [String] separator Separates item summary from item body. Defaults to <!--MORE--> | |
# | |
def article_summary(item, read_more_text="Read more...", separator="<!--MORE-->") | |
summary,body = item.compiled_content.split(separator) | |
return item.compiled_content unless body | |
link = link_to( (item[:read_more] || read_more_text), item.path, :class=>'readmore' ) | |
return summary+"<p class='readmore'>#{link}</p>" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment