aboutsummaryrefslogtreecommitdiff
path: root/bin/webring.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bin/webring.rb')
-rw-r--r--bin/webring.rb82
1 files changed, 82 insertions, 0 deletions
diff --git a/bin/webring.rb b/bin/webring.rb
new file mode 100644
index 0000000..86737be
--- /dev/null
+++ b/bin/webring.rb
@@ -0,0 +1,82 @@
1require "erb"
2require "htmlentities"
3require "open-uri"
4require "simple-rss"
5
6summary_max_length = 360
7
8feeds = [
9 "https://landley.net/rss.xml",
10 "https://drewdevault.com/feed.xml",
11 "https://offbeatpursuit.com/blog/index.rss",
12 "https://mirzapandzo.com/rss.xml",
13 "https://journal.valeriansaliou.name/rss/",
14 "https://neil.computer/rss/",
15 "https://michael.stapelberg.ch/feed.xml",
16 "https://utcc.utoronto.ca/~cks/space/blog/?atom",
17 "https://szymonkaliski.com/feed.xml"
18]
19
20out_html = ""
21decoder = HTMLEntities.new
22
23feeds.each do |feed_url|
24 begin
25 rss_content = URI.open(feed_url).read
26 rss = SimpleRSS.parse(rss_content)
27
28 first = rss.items.first
29 author = rss.channel.title
30 website = rss.channel.link
31 title = first.title
32 link = first.link
33
34 description = first.description
35 summary = description
36 content = first.content
37
38 if not summary
39 summary = content
40 end
41
42 summary.force_encoding("UTF-8")
43 summary = decoder.decode(summary)
44 .gsub(%r{</?[^>]+?>}, '')
45 .gsub(/\s{2,}/, ' ')
46 .gsub("\n", ' ')
47
48 if summary.length > summary_max_length
49 summary = "#{summary[0...summary_max_length]}..."
50 end
51
52 template = ERB.new <<-EOF
53 <li>
54 <a href="<%= link %>" target="_blank" rel="noopener"><%= title %></a>
55
56 <a href="<%= website %>" target="_blank" rel="noopener"><%= author %></a>
57 <div><%= summary %></div>
58 </li>
59 EOF
60
61 partial = template.result(binding)
62 out_html.concat(partial)
63
64 puts "Feed: #{author}"
65 puts "Title: #{title}"
66 puts "Link: #{link}"
67 puts "Summary: #{summary}"
68 puts
69 rescue OpenURI::HTTPError => e
70 puts "Failed to fetch #{url}: #{e.message}"
71 rescue SimpleRSSError => e
72 puts "Failed to parse #{url}: #{e.message}"
73 end
74end
75
76
77template = ERB.new <<-EOF
78 <h2>Posts from blogs I follow around the net</h2>
79 <ul><%= out_html %></ul>
80EOF
81out_html = template.result(binding)
82File.write("_includes/webring.html", out_html)