From 2417a6b7603524dc5cd30d29b153f91024b9443d Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Wed, 1 Nov 2023 22:54:27 +0100 Subject: Move to Jekyll --- bin/webring.rb | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 bin/webring.rb (limited to 'bin/webring.rb') 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 @@ +require "erb" +require "htmlentities" +require "open-uri" +require "simple-rss" + +summary_max_length = 360 + +feeds = [ + "https://landley.net/rss.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 +
  • + <%= title %> + — + <%= author %> +
    <%= summary %>
    +
  • + 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 +

    Posts from blogs I follow around the net

    + +EOF +out_html = template.result(binding) +File.write("_includes/webring.html", out_html) -- cgit v1.2.3