~sivers/sive.rs

sive.rs/script/tweets.rb -rwxr-xr-x 870 bytes
5fcf6634 — Derek Sivers cover and hardcover 18 hours ago
                                                                                
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
#!/usr/bin/env ruby
require_relative 'init.rb'

files = Dir[ROOT + 'content/tweets/*'].sort.reverse
template = File.read(ROOT + 'templates/tweets.mustache')

def parse(fn)
  res = {}
  res[:date] = File.basename(fn)[0, 10]
  d = Date.parse(res[:date])
  res[:showdate] = d.strftime('%B %-d, %Y')
  res[:isodate] = d.rfc3339
  res[:rawtweet] = File.read(fn).strip.gsub("'", '’')
  res[:tweet] = autolink(CGI.escapeHTML(res[:rawtweet]))
  res
end

tweets = files.map {|fn| parse(fn)}

vars = {}
vars[:bodyid] = 'tweets'
vars[:pagetitle] = 'tweets'
vars[:pagedescription] = 'all tweets'
vars[:tweets] = tweets.sort_by {|x| x[:date]}.reverse
wput('tweets', page(template, vars))

# https://twtxt.readthedocs.io/en/stable/
File.open(WEB_DIR + 'twtxt.txt', 'w') do |f|
  vars[:tweets].each do |t|
    f.puts "%s\t%s" % [t[:isodate], t[:rawtweet]]
  end
end

TWEETS = tweets