-require './walkdir'
+require 'page'
+require 'store'
+require 'walkdir'
-books = []
+outputDir = 'output'
+
+book_ids = []
+imageCount = 0
+
+def handleArg(arg)
+ if "--purge" == arg
+ puts 'Purging database...'
+ @store.dropSchema()
+ elsif arg.start_with?("--")
+ abort('ERROR: Unrecognized option "' + arg + '".')
+ end
+end
+
+@store = Store.new()
+@store.connect()
+
+for arg in ARGV
+ handleArg(arg)
+end
+
+@store.init_db()
for arg in ARGV
- w = WalkDir.new(arg)
- books.push(w.books)
+ if ! arg.start_with?("--")
+ puts 'Scanning directory "' + arg + '"...'
+ w = WalkDir.new(@store, arg)
+ book_ids += (w.books)
+ end
+end
+
+puts 'Creating output...'
+
+counts = {}
+
+('A'..'Z').each do |letter|
+ book_ids = @store.query_books_by_author(letter + '%')
+ puts 'Authors starting with "' + letter + '": ' + book_ids.length.to_s() + ' books.'
+ counts[letter] = book_ids.length
+
+ page = Page.new(@store)
+ if 'A' != letter
+ page.back = ['../output_' + (letter.ord - 1).chr + '/index.html', 'Prev']
+ end
+ if 'Z' != letter
+ page.forward = ['../output_' + (letter.ord + 1).chr + '/index.html', 'Next']
+ end
+ page.output_dir = 'output_' + letter
+ page.title = "Authors starting with '" + letter + "'"
+ page.up = ['../output/index.html', 'Index']
+
+ page.write_html(book_ids)
+end
+
+content = '<table><tr><th>Author</th><th>Books</th></tr>'
+('A'..'Z').each do |letter|
+ content += ' <tr><td><a href="../output_' + letter + '/index.html">Starting with ' + letter + '</a></td><td>' + counts[letter].to_s + '</td></tr>'
end
+page = Page.new(@store)
+page.output_dir = 'output'
+page.special = content
+page.write_html( [] )
+
+@store.disconnect()
-puts books