#!/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), 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 } xml = [' pdp8 https://pdp8.info music, pictures and videos en'] date = DateTime.now xml << " #{date.httpdate}" xml << " #{date.rfc3339}" items.sort_by { |i| i['dc:date'] }.each do |item| xml << ' ' item.each do |k, v| xml << " <#{k}>#{v}" end xml << ' ' end xml << ' ' File.open(File.join(WWW, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }