initial commit, it works
This commit is contained in:
commit
b8c449d9c9
27
index.html.erb
Normal file
27
index.html.erb
Normal file
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>The Secret Book Lending Site</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Author</th>
|
||||
<th>Link</th>
|
||||
</tr>
|
||||
<% books.each do |f, b| %>
|
||||
<tr>
|
||||
<td><%= b.title.content %></td>
|
||||
<td><%= b.creator.content %></td>
|
||||
<td><a href="<%= f %>">EPUB</a></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
39
index.rb
Normal file
39
index.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'gepub'
|
||||
require 'erb'
|
||||
|
||||
# Parse epubs
|
||||
|
||||
books = Dir["books/*.epub"].map do |f|
|
||||
[f, GEPUB::Book.parse(File.new f)]
|
||||
end
|
||||
|
||||
books = books.to_h
|
||||
|
||||
|
||||
# Collection of sort_by procs
|
||||
|
||||
author_surname_sort_by = proc { |filename, book|
|
||||
book.creator.content.split(" ")[-1]
|
||||
}
|
||||
|
||||
title_sort_by = proc { |filename, book|
|
||||
book.title.content
|
||||
}
|
||||
|
||||
|
||||
# Sort books by one of the above
|
||||
|
||||
books = books.sort_by &title_sort_by
|
||||
|
||||
|
||||
# Generate 'index.html' from template
|
||||
|
||||
bind = binding
|
||||
bind.local_variable_set(:books, books)
|
||||
|
||||
template = File.read 'index.html.erb'
|
||||
|
||||
result = ERB.new(template).result(bind)
|
||||
File.open "index.html", "w+" do |f|
|
||||
f << result
|
||||
end
|
Loading…
Reference in New Issue
Block a user