Improve metadata extraction from epubs, and clean up the display of popups in the...
[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 'span.popup {  }'
30   fd.puts 'span.popup:hover {text-decoration: none; background: #cfffff; z-index: 6; }'
31   fd.puts 'span.popup span {display: none; position: absolute; '
32   fd.puts '  margin: 4px 0 0 0px; padding: 3px 3px 3px 3px;'
33   fd.puts '  border-style:solid; border-color:black; border-width:1px;}'
34   fd.puts 'span.popup:hover span {display: block; margin: 20px 0 0 0px; background: #ffffaf; z-index:6;}'
35   fd.puts '    </style>'
36   fd.puts '  </head>'
37   fd.puts '  <body>'
38   
39   for book in books
40     image = nil
41     if nil != book.cover
42       imageCount += 1
43       (path, mimeType) = book.cover.writeImage(outputDir, 'image' + imageCount.to_s)
44       image = '<img height="200px" src="' + path + '"/>'
45     else
46       image = '(No cover image)'
47     end
48
49     fd.puts '    <div><table>'
50     fd.puts '      <tr><td><a href="' + book.path + '">' + image + '</a></td>'
51
52     heading = book.heading()
53     description = book.description()
54     if nil != description
55       fd.puts '          <td><span class="popup">' + heading + '<span><p>' + heading + '</p><p>' + description + '</p></span></span></td></tr>'
56     else
57       fd.puts '          <td>' + heading + '</td></tr>'
58     end
59       
60     fd.puts '    </table></div>'
61   end
62   
63   fd.puts "    </table>"
64   fd.puts "  </body>"
65   fd.puts "</html>"
66 end
67