diff options
Diffstat (limited to 'rss.rb')
-rwxr-xr-x | rss.rb | 40 |
1 files changed, 23 insertions, 17 deletions
@@ -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: '<![CDATA[' + File.read(File.join(dir, 'README')).chomp.sub(/^\n/, '').sub("\n\n", "\n") + ']]>', + description: "<![CDATA[#{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 = ['<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" @@ -62,7 +68,7 @@ xml = ['<?xml version="1.0" encoding="UTF-8"?> date = DateTime.now xml << " <pubDate>#{date.httpdate}</pubDate>" -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>' item.each do |k, v| xml << " <#{k}>#{v}</#{k}>" @@ -72,4 +78,4 @@ end xml << ' </channel> </rss>' -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") } |