1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/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: "<![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))
# 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: '<![CDATA[' + note['content'] + ']]>',
# pubDate: Date.parse(note['published']).httpdate
# }
# end
# jj items.sort_by { |i| DateTime.parse(i[:pubDate]) }.reverse
xml = ['<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>pdp8</title>
<link>https://pdp8.info</link>
<description>music, pictures and videos</description>
<language>en</language>
<atom:link href="https://pdp8.info/rss.xml" rel="self" type="application/rss+xml" /> ']
date = DateTime.now
xml << " <pubDate>#{date.httpdate}</pubDate>"
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}>"
end
xml << ' </item>'
end
xml << ' </channel>
</rss>'
File.open(File.join(WWW_DIR, 'rss.xml'), 'w+') { |f| f.puts xml.join("\n") }
|