diff options
Diffstat (limited to 'rss.rb')
-rwxr-xr-x | rss.rb | 71 |
1 files changed, 45 insertions, 26 deletions
@@ -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") } |