Improve HTML formatting. Handle more variants of EPUB.
[quanlib.git] / main.rb
1 require 'walkdir'
2
3 outputDir = 'output'
4
5 books = []
6 imageCount = 0
7
8 for arg in ARGV
9   w = WalkDir.new(arg)
10   books += (w.books)
11 end
12
13 if ! Dir.exist?(outputDir)
14   Dir.mkdir(outputDir)
15 end
16
17 open(outputDir + '/index.html', 'w') do |fd|
18   fd.puts '<html>'
19   fd.puts '  <head>'
20   fd.puts '    <meta charset="utf-8"/>'
21   fd.puts '    <title>Books</title>'
22   fd.puts '    <style>'
23   fd.puts 'div { '
24   fd.puts '  display: inline-block;'
25   fd.puts '  width: 400px;'
26   fd.puts '  margin: 10px;'
27   fd.puts '  border 3px solid #73ad21;'
28   fd.puts '}'
29   fd.puts '    </style>'
30   fd.puts '  </head>'
31   fd.puts '  <body>'
32   
33   for book in books
34     image = nil
35     if nil != book.cover
36       imageCount += 1
37       (path, mimeType) = book.cover.writeImage(outputDir, 'image' + imageCount.to_s)
38       image = '<img height="200px" src="' + path + '"/>'
39     else
40       image = '(No cover image)'
41     end
42
43     fd.puts '    <div><table>'
44     fd.puts '      <tr><td><a href="' + book.path + '">' + image + '</a></td><td>' + book.describe() + '</td></tr>'
45     fd.puts '    </table></div>'
46   end
47   
48   fd.puts "    </table>"
49   fd.puts "  </body>"
50   fd.puts "</html>"
51 end
52