diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-01 22:54:27 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-01 22:54:27 +0100 |
| commit | 2417a6b7603524dc5cd30d29b153f91024b9443d (patch) | |
| tree | 9be5ea8e5baba96dd9159217da6badf6157fb595 /bin/webring.rb | |
| parent | 89ba3497f07a8ea43d209b583f39fcc286acc923 (diff) | |
| download | mitjafelicijan.com-2417a6b7603524dc5cd30d29b153f91024b9443d.tar.gz | |
Move to Jekyll
Diffstat (limited to 'bin/webring.rb')
| -rw-r--r-- | bin/webring.rb | 82 |
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 @@ | |||
| 1 | require "erb" | ||
| 2 | require "htmlentities" | ||
| 3 | require "open-uri" | ||
| 4 | require "simple-rss" | ||
| 5 | |||
| 6 | summary_max_length = 360 | ||
| 7 | |||
| 8 | feeds = [ | ||
| 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 | |||
| 20 | out_html = "" | ||
| 21 | decoder = HTMLEntities.new | ||
| 22 | |||
| 23 | feeds.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 | ||
| 74 | end | ||
| 75 | |||
| 76 | |||
| 77 | template = ERB.new <<-EOF | ||
| 78 | <h2>Posts from blogs I follow around the net</h2> | ||
| 79 | <ul><%= out_html %></ul> | ||
| 80 | EOF | ||
| 81 | out_html = template.result(binding) | ||
| 82 | File.write("_includes/webring.html", out_html) | ||
