aboutsummaryrefslogtreecommitdiff
blob: 133fc102453c3b049d01849e5afa31e5be356d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Gentoo
  class PlanetGenerator < Jekyll::Generator
    PLANET_XML = '_data/planet.xml'

    def generate(site)
      planetinfo = Nokogiri::XML(File.open(PLANET_XML))
      # author is the only thing taken from the dublin core, we don't need namespaces for that
      planetinfo.remove_namespaces!

      site.data['planet'] ||= { 'posts' => [] }

      planetinfo.xpath('/rss/channel/item').each do |item|
        item_data = {}
        ignore = false

        item.children.each do |tag|
          case tag.name
          when 'title'
            item_data['title'] = tag.text.strip
          when 'link'
            item_data['uri'] = tag.text
          when 'creator'
            if tag.text =~ /^(.*) \(([^)]+)\)$/
              item_data['author'] = $1
              item_data['nick'] = $2
            else
              # It's a news item; skip
              ignore = true
            end
          end
        end

        site.data['planet']['posts'] << item_data unless ignore
      end
    end
  end
end