Module: JekyllWebring

Defined in:
lib/jekyll-webring.rb

Constant Summary collapse

TEMPLATE =
<<~HTML
	<section class="webring">
		<h3>Articles from blogs I follow around the net</h3>
		<section class="articles">
			{% for item in webring %}
			<div class="article">
				<h4 class="title">
					<a href="{{ item.url }}" target="_blank" rel="noopener">{{ item.title }}</a>
				</h4>
				<p class="summary">{{ item.summary }}</p>
				<small class="source">
					via <a href="{{ item.source_url }}">{{ item.source_title }}</a>
				</small>
				<small class="date">{{ item.date }}</small>
			</div>
			{% endfor %}
		</section>
	</section>
HTML

Class Method Summary collapse

Class Method Details

.configObject



45
46
47
# File 'lib/jekyll-webring.rb', line 45

def self.config ()
	@config
end

.feedsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/jekyll-webring.rb', line 108

def self.get_data (site)
	unless @data
		@data = site.data['webring'] || {}
	end

	@data
end

.set_config(context) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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