From cd53a2fe5fc8baf9750fbd2d9b0b4c855d8694a7 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Mon, 29 Jul 2024 14:21:31 +0200 Subject: rss sorting fixed, rss limited to 25 items, fediring --- rss.rb | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'rss.rb') diff --git a/rss.rb b/rss.rb index eb163d4..68c9632 100755 --- a/rss.rb +++ b/rss.rb @@ -1,28 +1,41 @@ #!/usr/bin/env ruby +require_relative 'lib' require 'date' +require 'time' require 'json' -MEDIA = '/srv/media/' -SOCIAL = '/srv/social/outbox/object/note/' -WWW = '/srv/www/pdp8-test/' +# SOCIAL = '/srv/social/outbox/object/note/' items = [] -%w[music videos].each do |cat| - Dir[File.join(MEDIA, cat, '*')].each do |dir| +%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: File.basename(dir).split('_')[1..-1].join(' '), + title: title, link: File.join('https://pdp8.info', cat + '.html#' + date), guid: File.join('https://pdp8.info', cat + '.html#' + date), - description: '', + 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)) @@ -39,14 +52,7 @@ end # } # end -date = Dir[File.join(MEDIA, 'pictures', '*.jpeg')].last.split('_')[0] -updated = Date.parse(date) -items << { - title: 'pictures', - link: 'https://pdp8.info/pictures.html', - guid: 'https://pdp8.info/pictures.html', - pubDate: updated.httpdate -} +# jj items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse xml = [' date = DateTime.now xml << " #{date.httpdate}" -items.sort_by { |i| i['pubDate'] }.each do |item| +items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse[0..24].each do |item| xml << ' ' item.each do |k, v| xml << " <#{k}>#{v}" @@ -72,4 +78,4 @@ end xml << ' ' -File.open(File.join(WWW, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") } +File.open(File.join(WWW_DIR, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") } -- cgit v1.2.3