diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/vault.rb | 60 | ||||
| -rw-r--r-- | bin/webring.rb | 80 |
2 files changed, 0 insertions, 140 deletions
diff --git a/bin/vault.rb b/bin/vault.rb deleted file mode 100644 index 1a664ea..0000000 --- a/bin/vault.rb +++ /dev/null | |||
| @@ -1,60 +0,0 @@ | |||
| 1 | require 'nokogiri' | ||
| 2 | require 'net/http' | ||
| 3 | require 'uri' | ||
| 4 | |||
| 5 | url = "https://mitjafelicijan.fra1.digitaloceanspaces.com/" | ||
| 6 | |||
| 7 | def truncate_filename(filename, max_length) | ||
| 8 | return filename if filename.length <= max_length | ||
| 9 | |||
| 10 | file_extension = filename.split('.').last | ||
| 11 | "#{filename[0...max_length - file_extension.length - 5]}….#{file_extension}" | ||
| 12 | end | ||
| 13 | |||
| 14 | uri = URI(url) | ||
| 15 | response = Net::HTTP.get_response(uri) | ||
| 16 | |||
| 17 | if response.is_a?(Net::HTTPSuccess) | ||
| 18 | xml_data = response.body | ||
| 19 | root = Nokogiri::XML(xml_data) | ||
| 20 | |||
| 21 | root.remove_namespaces! | ||
| 22 | tree = {} | ||
| 23 | |||
| 24 | root.xpath("//Contents").each do |content| | ||
| 25 | key = content.xpath("Key").text | ||
| 26 | parts = key.split("/") | ||
| 27 | node = tree | ||
| 28 | parts.each do |part| | ||
| 29 | next if part.empty? | ||
| 30 | node[part] ||= {} | ||
| 31 | node = node[part] | ||
| 32 | end | ||
| 33 | end | ||
| 34 | |||
| 35 | def tree_to_md(tree, url, indent = 0, path = "") | ||
| 36 | md = "" | ||
| 37 | tree.each do |k, v| | ||
| 38 | if v.empty? # If the node is empty, it's a file | ||
| 39 | file_url = "#{url}#{path}#{k}" | ||
| 40 | file_name = truncate_filename(k, 500) | ||
| 41 | md += "#{" " * indent}- [#{file_name}](#{file_url})\n" | ||
| 42 | else # If the node has children, it's a directory | ||
| 43 | md += "#{" " * indent}- #{k}\n" | ||
| 44 | md += tree_to_md(v, url, indent + 1, "#{path}#{k}/") | ||
| 45 | end | ||
| 46 | end | ||
| 47 | md | ||
| 48 | end | ||
| 49 | |||
| 50 | md = tree_to_md(tree, url) | ||
| 51 | puts md | ||
| 52 | |||
| 53 | File.open("_layouts/vault.md", "r") do |file| | ||
| 54 | content = file.read | ||
| 55 | new_content = content.gsub("{CONTENT}", md) | ||
| 56 | File.open("vault.md", "w") { |f| f.write(new_content) } | ||
| 57 | end | ||
| 58 | else | ||
| 59 | puts "Failed to fetch XML data. Status code: #{response.code}" | ||
| 60 | end | ||
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) | ||
