Class: ZRSS

Inherits:
Zarchitect show all
Defined in:
lib/zarchitect/rss.rb

Constant Summary

Constants inherited from Zarchitect

Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION

Instance Method Summary collapse

Methods inherited from Zarchitect

#main, #rss

Constructor Details

#initializeZRSS

Returns a new instance of ZRSS.



3
4
5
# File 'lib/zarchitect/rss.rb', line 3

def initialize
  @items = Array.new
end

Instance Method Details

#buildObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zarchitect/rss.rb', line 21

def build
  rss = RSS::Maker.make("atom") do |maker|
    maker.channel.title = Zarchitect.conf.site_name
    maker.channel.author = Zarchitect.conf.admin
    maker.channel.updated = Time.now.to_s
    maker.channel.about = Zarchitect.conf.site_description
    maker.channel.link = Zarchitect.conf.url

    @items.each do |item|
      maker.items.new_item do |rss_item|
        rss_item.title = item.title
        rss_item.pubDate = item.dates
        rss_item.description = item.description
        rss_item.link = item.link
        #rss_item.guid = item.guid
      end
    end
  end

  #write rss
  File.open("_html/feed.rss", "w") { |f| f.write(rss) }
end

#try_item(page) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zarchitect/rss.rb', line 7

def try_item(page)
  return if page.draft
  return unless page.rss?
  if @items.count < Zarchitect.conf.rss_size # simply add page to rss items
    @items.push RSSItem.new(page)
  else # check if it's more recent than the oldest item in the feed
    if page.date > @items.last.date
      @items.pop
      @items.push RSSItem.new(page)
    end
  end
  @items.sort_by! { |i| i.date }.reverse!
end