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
38
39
40
41
42
43
44
45
46
47
48
49
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
|
require "erb"
require "htmlentities"
require "open-uri"
require "simple-rss"
summary_max_length = 320
feeds = [
"https://blog.regehr.org/feed",
"https://www.neilhenning.dev/index.xml",
"https://drewdevault.com/feed.xml",
"https://offbeatpursuit.com/blog/index.rss",
"https://mirzapandzo.com/rss.xml",
"https://journal.valeriansaliou.name/rss/",
"https://neil.computer/rss/",
"https://michael.stapelberg.ch/feed.xml",
"https://utcc.utoronto.ca/~cks/space/blog/?atom",
"https://szymonkaliski.com/feed.xml"
]
out_html = ""
decoder = HTMLEntities.new
feeds.each do |feed_url|
begin
rss_content = URI.open(feed_url).read
rss = SimpleRSS.parse(rss_content)
first = rss.items.first
author = rss.channel.title
website = rss.channel.link
title = first.title
link = first.link
description = first.description
summary = description
content = first.content
if not summary
summary = content
end
summary.force_encoding("UTF-8")
summary = decoder.decode(summary)
.gsub(%r{</?[^>]+?>}, '')
.gsub(/\s{2,}/, ' ')
.gsub("\n", ' ')
if summary.length > summary_max_length
summary = "#{summary[0...summary_max_length]}..."
end
template = ERB.new <<-EOF
<li>
<a href="<%= link %>" target="_blank" rel="noopener"><%= title %></a>
—
<a href="<%= website %>" target="_blank" rel="noopener"><%= author %></a>
<div><%= summary %></div>
</li>
EOF
partial = template.result(binding)
out_html.concat(partial)
puts "Feed: #{author}"
puts "Title: #{title}"
puts "Link: #{link}"
puts "Summary: #{summary}"
puts
rescue OpenURI::HTTPError => e
puts "Failed to fetch #{url}: #{e.message}"
rescue SimpleRSSError => e
puts "Failed to parse #{url}: #{e.message}"
end
end
template = ERB.new <<-EOF
<h2>Posts from blogs I follow around the net</h2>
<ul><%= out_html %></ul>
EOF
out_html = template.result(binding)
File.write("_includes/webring.html", out_html)
|