summaryrefslogtreecommitdiff
path: root/rss.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-07-29 14:21:31 +0200
committerpdp8 <pdp8@pdp8.info>2024-07-29 14:21:31 +0200
commitcd53a2fe5fc8baf9750fbd2d9b0b4c855d8694a7 (patch)
tree689c156602c61da3a8ea177e49ec10590f1f6fd0 /rss.rb
parentd987641d7b68fcfa8431b1835411bb1095a37961 (diff)
rss sorting fixed, rss limited to 25 items, fediring
Diffstat (limited to 'rss.rb')
-rwxr-xr-xrss.rb40
1 files changed, 23 insertions, 17 deletions
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: '<![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") }