Module: Nanoc::Feeds::Helpers::Feeds

Includes:
Helpers::Blogging
Included in:
Nanoc::Feeds
Defined in:
lib/nanoc/feeds/helpers/feeds.rb

Instance Method Summary collapse

Instance Method Details

#feed(params = {}) ⇒ Object

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :limit (Number)
  • :articles (Array)
  • :id_proc (Proc)
  • :title (String)


13
14
15
16
17
18
19
# File 'lib/nanoc/feeds/helpers/feeds.rb', line 13

def feed(params = {})
  if @rep.name == :json
    json_feed(params)
  else
    atom_feed(params)
  end
end

#json_feed(params = {}) ⇒ Object

Parameters:

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :limit (Number)
  • :articles (Array)
  • :id_proc (Proc)
  • :title (String)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nanoc/feeds/helpers/feeds.rb', line 25

def json_feed(params = {})
  articles = params[:articles] || articles # articles is a helper method from Nanoc::Helpers::Blogging
  articles = articles.first(params[:limit]) if params[:limit]
  title = params[:title] || @config[:title]
  id_proc = params[:id_proc] || Proc.new { |article| atom_tag_for(article) }

  feed_items = articles.map { |article| build_for_article(article, title, id_proc:) }
  {
    version: "https://jsonfeed.org/version/1.1",
    title: title,
    home_page_url: "#{@config[:base_url]}",
    feed_url: feed_url,
    items: feed_items
  }.to_json
end