#!/usr/bin/env ruby require_relative 'lib' require 'date' require 'time' require 'json' # SOCIAL = '/srv/social/outbox/object/note/' 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 MEDIA_DIR, 'pictures', 'albums', '*'].each do |album| items << { title: File.basename(album).sub('_', ' '), link: File.join('https://pdp8.info', 'pictures.html#' + File.basename(album)), guid: File.join('https://pdp8.info', 'pictures.html#' + File.basename(album)), pubDate: File.mtime(album).httpdate } end # duplication of music/video posts? # Dir[File.join(SOCIAL, '*.json')].each do |json| # note = JSON.parse(File.read(json)) # next unless note['attributedTo'] == 'https://social.pdp8.info/pdp8' and note['to'].include?('https://www.w3.org/ns/activitystreams#Public') # # # TODO: add enclosures for attachments # # tags # items << { # title: note['published'], # link: 'https://pdp8.info/social/create.html#' + note['published'], # guid: note['id'], # description: '', # pubDate: Date.parse(note['published']).httpdate # } # 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") }