~sivers/sive.rs

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

files = Dir[ROOT + 'content/books/*']
template = File.read(ROOT + 'templates/book.mustache')

def parse(fn)
  res = meta(fn)
  res[:notes] = CGI.escapeHTML(body(fn)).gsub("\n", "<br>\n")
  res[:uri] = File.basename(fn)
  res[:bodyid] = 'book'
  res[:pagetitle] = res[:title].dup
  res[:pagedescription] = 'notes from the book'
  res
end

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

books.each do |book|
  wput('book/' + book[:uri], page(template, book))
end

vars = {}
vars[:bodyid] = 'booklist'
vars[:pagetitle] = 'book notes'
vars[:pagedescription] = 'notes from books I’ve read'
vars[:books] = books.sort_by do |x|
  '%02d%s' % [x[:rating], x[:date]]
end.reverse
wput('book/home', page(File.read(ROOT + 'templates/books.mustache'), vars))