summaryrefslogtreecommitdiff
path: root/rss.rb
blob: 554d45cb1183b5d6e60d91f978b38ff257d47c10 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env ruby
require 'date'
MEDIA = '/srv/media/'
WWW = '/srv/www/pdp8-test/'
items = []
%w[music videos].each do |cat|
  Dir[File.join(MEDIA, cat, '*')].each do |dir|
    date = File.basename(dir).split('_')[0]
    updated = Date.parse(date) # .strftime('%Y-%m-%d')
    items << {
      title: File.basename(dir).split('_')[1..-1].join(' '),
      link: File.join('https://pdp8.info', cat + '.html#' + date),
      guid: File.join('https://pdp8.info', cat + '.html#' + date),
      description: File.read(File.join(dir, 'README')).chomp.sub(/^\n/, '').sub("\n\n", "\n"),
      pubDate: updated.httpdate
      # 'dc:date' => updated.rfc3339
    }
  end
end
date = Dir[File.join(MEDIA, 'pictures', '*.jpeg')].last.split('_')[0]
updated = Date.parse(date) # .strftime('%Y%m%d')
items << {
  title: 'pictures',
  link: 'https://pdp8.info/pictures.html',
  guid: 'https://pdp8.info/pictures.html',
  pubDate: updated.httpdate
  # 'dc:date' => updated.rfc3339
}

xml = ['<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  <channel>
    <title>pdp8</title>
    <link>https://pdp8.info</link>
    <description>music, pictures and videos</description>
    <language>en</language>']
date = DateTime.now
xml << "    <pubDate>#{date.httpdate}</pubDate>"
# xml << "    <dc:date>#{date.rfc3339}</dc:date>"

items.sort_by { |i| i['pubDate'] }.each do |item|
  xml << '    <item>'
  item.each do |k, v|
    xml << "      <#{k}>#{v}</#{k}>"
  end
  xml << '    </item>'
end
xml << '  </channel>
</rss>'

File.open(File.join(WWW, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }