summaryrefslogtreecommitdiff
path: root/rss.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-07-30 16:45:03 +0200
committerpdp8 <pdp8@pdp8.info>2023-07-30 16:45:03 +0200
commita3ab009e96db2269dcf3f6dd1c103aa885186ee4 (patch)
tree2ace6b0a9f056ee8929c673c52a72e12dbd30e02 /rss.rb
parentfc32ef98dfb83b69d02a31387cf4cdae96e520cd (diff)
media moved to media.pdp8.info, drone release
Diffstat (limited to 'rss.rb')
-rwxr-xr-xrss.rb71
1 files changed, 45 insertions, 26 deletions
diff --git a/rss.rb b/rss.rb
index b700f55..47b47c0 100755
--- a/rss.rb
+++ b/rss.rb
@@ -1,32 +1,51 @@
#!/usr/bin/env ruby
-require "rss"
+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),
+ 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',
+ pubDate: updated.httpdate,
+ 'dc:date' => updated.rfc3339
+}
-ROOT = ARGV[0]
+xml = ['<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0"
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+ <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>"
-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")
+items.sort_by { |i| i['dc:date'] }.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(ROOT, "rss.xml"), "w+") { |f| f.puts rss }
+File.open(File.join(WWW, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }