Skip to content

Commit

Permalink
Add item rep for the blog feed. Fixes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
cdchapman committed Nov 7, 2016
1 parent e250474 commit 572c69e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions content/blog/feed.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ is_hidden_from_human_search: true
author_name: @config[:blog][:author_name],
author_uri: @config[:blog][:author_uri],
articles: published_blog_posts,
content_proc: ->(post) { prepare_item_for_feed(post) },
excerpt_proc: ->(post) { prepare_item_for_feed(post, summary: true) },
content_proc: ->(post) { post.compiled_content(rep: :feed_entry) },
excerpt_proc: ->(post) { post_summary(post.reps.fetch(:feed_entry)) },
limit: 10
%>
15 changes: 12 additions & 3 deletions lib/helpers/blogging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,20 @@ def archive_years(posts = nil)
years.to_a
end

def post_summary(post, read_more_text: "Read more ⇢", separator: "<!--MORE-->")
summary, body = post.compiled_content.split(separator)
def post_summary(post_rep, read_more_text: "Read more ⇢", separator: "<!--MORE-->")
post_rep = case post_rep
when Nanoc::ItemRepView
post_rep
when Nanoc::ItemWithRepsView
post_rep.reps.fetch(:default)
else
raise ArgumentError, "Cannot summarize #{item_rep.inspect} (expected an item rep or an item, not a #{item_rep.class.name})"
end

summary, body = post_rep.compiled_content.split(separator)
return summary unless body

link = link_to(post.fetch(:read_more, read_more_text), post, class: "readmore", title: "Read the full article")
link = link_to(post_rep.item.fetch(:read_more, read_more_text), post_rep.item, global: post_rep.name != :default, class: "readmore", title: "Read the full article")
summary << %[<p class="readmore">#{link}</p>]
end

Expand Down
9 changes: 9 additions & 0 deletions rules/blog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@
filter :cache_buster if @config[:production]
filter :html5small if @config[:production]
end

compile '/static/blog/**/*.md', rep: :feed_entry do
filter :erb, @config[:erb]
filter :kramdown, @config[:kramdown]
filter :colorize_syntax,
default_colorizer: :rouge
filter :absolutify_paths, type: :html, global: true
filter :rubypantsunicode
end

0 comments on commit 572c69e

Please sign in to comment.