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