#!/usr/bin/env ruby require_relative 'lib' require 'date' require 'time' require 'json' items = [] %w[music videos climbing].each do |cat| Dir[File.join(MEDIA_DIR, cat, '*')].each do |dir| next unless File.basename(dir).match(/^\d/) date = File.basename(dir).split('_')[0] updated = Date.parse(date) title = File.basename(dir).split('_')[1..-1].join(' ') description = File.read(File.join(dir, 'README')).chomp.sub(/^\n/, '').sub("\n\n", "\n") title = description if title.empty? # title = date if title.empty? items << { title: title, link: File.join('https://pdp8.info', cat + '.html#' + date), guid: File.join('https://pdp8.info', cat + '.html#' + date), description: "", pubDate: updated.httpdate } end end Dir[File.join(OUTBOX_DIR, 'create', '*.json')] .collect { |f| JSON.load_file(f) } .select { |a| a['to'].include?('https://www.w3.org/ns/activitystreams#Public') } .select { |a| a['object'] and a['object']['attachment'] } .collect { |a| a['object'] } .each do |object| updated = Date.parse object['published'] object['attachment'].each do |a| next unless a['url'] =~ %r{pictures/webp} and a['mediaType'] == 'image/webp' items << { title: a['name'], link: a['url'], guid: a['url'], description: "]]>", pubDate: updated.httpdate } end end # jj items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse xml = [' pdp8 https://pdp8.info music, pictures and videos en '] date = DateTime.now xml << " #{date.httpdate}" items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse[0..24].each do |item| xml << ' ' item.each do |k, v| xml << " <#{k}>#{v}" end xml << ' ' end xml << ' ' File.open(File.join(WWW_DIR, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }