summaryrefslogtreecommitdiff
path: root/rss.rb
blob: b700f55402fdfa7ef6242c60d563445f35a53280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env ruby
require "rss"

ROOT = ARGV[0]

rss = RSS::Maker.make("2.0") do |maker|
  maker.channel.language = "en"
  maker.channel.author = "pdp8"
  maker.channel.updated = Time.now.to_s
  maker.channel.link = "https://pdp8.info"
  maker.channel.title = "pdp8"
  maker.channel.description = "music, pictures and videos"
  ["music", "videos"].each do |cat|
    Dir[File.join(ROOT, cat, "*")].each do |dir|
      maker.items.new_item do |item|
        item.title = File.basename(dir).split("_")[1..-1].join(" ")
        date = File.basename(dir).split("_")[0]
        item.link = File.join("https://pdp8.info", cat + ".html#" + date)
        item.updated = Time.parse(date).strftime("%Y-%m-%d")
        item.description = File.read(File.join(dir, "README")).chomp.sub(/^\n/, '').sub("\n\n", "\n")
      end
    end
  end
  maker.items.new_item do |item|
    item.title = "pictures"
    item.link = "https://pdp8.info/pictures.html"
    date = Dir[File.join(ROOT, "pictures", "*.jpeg")].last.split("_")[0]
    item.updated = Time.parse(date).strftime("%Y%m%d")
  end
end

File.open(File.join(ROOT, "rss.xml"), "w+") { |f| f.puts rss }