Module: Postwave::RssHelper

Includes:
BlogUtilities
Included in:
BlogBuilder
Defined in:
lib/postwave/rss_helper.rb

Defined Under Namespace

Classes: FeedPost

Constant Summary

Constants included from BlogUtilities

BlogUtilities::CONFIG_FILE_NAME, BlogUtilities::INDEX_FILE_NAME, BlogUtilities::META_DIR, BlogUtilities::POSTS_DIR, BlogUtilities::RSS_FILE_NAME, BlogUtilities::SUMMARY_FILE_NAME, BlogUtilities::TAGS_DIR

Instance Method Summary collapse

Methods included from BlogUtilities

#config_values, #directory_paths, #file_paths, #find_missing_paths, #is_set_up?

Instance Method Details

#build_rss(posts) ⇒ Object



11
12
13
14
15
# File 'lib/postwave/rss_helper.rb', line 11

def build_rss(posts)
  File.open(File.join(Dir.pwd, POSTS_DIR, META_DIR, RSS_FILE_NAME), "w") do |rss|
    rss << feed_content(posts)
  end
end

#feed_content(posts) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/postwave/rss_helper.rb', line 17

def feed_content(posts)
  link = config_values[:url]
  updated = Time.now.iso8601.to_s
  title = config_values[:name]
  description = config_values[:description]

  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, fenced_code_blocks: true)
  feed_posts = posts.map do |post|
    post_link = "#{config_values[:url]}/#{config_values[:posts_path]}/#{post.slug}"
    html_body = CGI.unescapeHTML(markdown.render(post.body))
    FeedPost.new(post.title, post_link, html_body, post.date.iso8601, post.tags)
  end

  path = File.join(__dir__, "templates/feed.erb")
  template = File.read(path)
  renderer = ERB.new(template)
  renderer.result(binding)
end