module JekyllWebring

Constants

TEMPLATE

Public Class Methods

config() click to toggle source
# File lib/jekyll-webring.rb, line 45
def self.config ()
        @config
end
feeds() click to toggle source
# File lib/jekyll-webring.rb, line 50
def self.feeds ()
        urls = config['feeds']

        if urls.empty?
                return [];
        end

        if @feeds.empty?
                Jekyll.logger.info("Webring:", "fetching rss feeds")

                urls.each do |url|
                        Jekyll.logger.debug("Webring:",
                                "fetching feed at #{ url }")

                        feed = []

                        begin
                                xml = HTTParty.get(url).body
                        rescue
                                Jekyll.logger.error("Webring:",
                                        "unable to fetch feed at #{ url }")
                                next
                        end

                        begin
                                raw_feed = Feedjira.parse(xml)
                        rescue
                                Jekyll.logger.error("Webring:",
                                        "unable to parse feed fetched from #{ url }")
                                next
                        end

                        raw_feed.entries.each do |item|
                                sanitized = Sanitize.fragment(
                                        item.content || item.summary)

                                summary = sanitized.length > config['max_summary_length'] ?
                                        "#{ sanitized[0 ... config['max_summary_length']] }..." : sanitized

                                feed_item = {
                                        'source_title' => raw_feed.title,
                                        'source_url'   => raw_feed.url,
                                        'title'        => item.title,
                                        'url'          => item.url,
                                        '_date'        => item.published,
                                        'summary'      => summary,
                                }

                                feed << feed_item
                        end
                        @feeds << feed
                end
        end

        @feeds
end
get_data(site) click to toggle source
# File lib/jekyll-webring.rb, line 108
def self.get_data (site)
        unless @data
                @data = site.data['webring'] || {}
        end

        @data
end
set_config(context) click to toggle source
# File lib/jekyll-webring.rb, line 30
def self.set_config (context)
        jekyll_config = context.registers[:site].config
        config = jekyll_config['webring'] || {}

        @config ||= {
                'feeds'                     => config['feeds'] || [],
                'layout_file'               => config['layout_file'] ? "#{ jekyll_config['layouts_dir'] }/#{ config['layout_file'] }.html" : '',
                'data_file'                 => config['data_file']   ? "#{ jekyll_config['data_dir'] }/#{ config['data_file'] }.yml" : '',
                'date_format'               => jekyll_config['date_format'] || config['date_format'] || "%-d %B, %Y",
                'max_summary_length'        => config['max_summary_length'] || 256,
                'no_item_at_date_behaviour' => config['no_item_at_date_behaviour'],
                'num_items'                 => config['num_items'] || 3,
        }
end