TOC generator for issue-based blogging on tangled
gen_blog_index.rb
1require 'httparty'
2require 'nokogiri'
3require 'time'
4
5URL = "https://tangled.org/did:plc:3qvnhzaejch2aycm6gnu7rma/blog/issues"
6AGENT = { "User-Agent" => "Mozilla/5.0" }
7
8res = HTTParty.get(URL, headers: AGENT)
9return puts "Failed: #{res.code}" unless res.success?
10
11doc = Nokogiri::HTML(res.body)
12
13issues = doc.css("div.rounded.drop-shadow-sm.bg-white").filter_map do |node|
14 link = node.at_css("a.no-underline")
15 time = node.at_css("span time")
16 next unless link && time
17 date = Time.iso8601(time['datetime']).strftime("%b %-d, %Y")
18 title = link.text.split('#').first.strip
19 "#{date} [#{title}](https://tangled.org#{link['href']})"
20end
21
22content = "beware! informal ramblings and disorganized notes abound, also only the last 30 posts are listed below.\n\n" + issues.join("\n\n")
23File.write("README.md", content)
24
25puts "Done!"