projects
/
quanlib.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e9d890a
)
Improve metadata extraction from epubs, and clean up the display of popups in the...
author
Chris Jaekl
<cejaekl@yahoo.com>
Tue, 28 Feb 2017 14:40:07 +0000
(23:40 +0900)
committer
Chris Jaekl
<cejaekl@yahoo.com>
Tue, 28 Feb 2017 14:40:07 +0000
(23:40 +0900)
book.rb
patch
|
blob
|
history
main.rb
patch
|
blob
|
history
diff --git
a/book.rb
b/book.rb
index f59b61a66ea44d17a86e7d999e34496b84fbea99..3cf513957c0a2cc4173266857c95952b8cc0bb14 100644
(file)
--- a/
book.rb
+++ b/
book.rb
@@
-6,9
+6,12
@@
require 'author'
require 'cover'
class Book
require 'cover'
class Book
+ @@DC_NS_URL = 'http://purl.org/dc/elements/1.1/'
+
def initialize(fileName)
@author = nil
@cover = nil
def initialize(fileName)
@author = nil
@cover = nil
+ @description = nil
@path = fileName
@series = nil
@title = nil
@path = fileName
@series = nil
@title = nil
@@
-36,7
+39,11
@@
class Book
return @cover
end
return @cover
end
- def describe
+ def description
+ @description
+ end
+
+ def heading
result = []
if nil != @title
result = []
if nil != @title
@@
-45,7
+52,7
@@
class Book
result.push('<i>(Unknown title)</i>')
end
if nil != @author
result.push('<i>(Unknown title)</i>')
end
if nil != @author
- result.push(
@author.to_s()
)
+ result.push(
'<i>by ' + @author.to_s() + '</i>'
)
end
seriesInfo = []
end
seriesInfo = []
@@
-191,13
+198,13
@@
class Book
#-------
# Author
#-------
# Author
- creator
= opfDoc.css('dc|creator', 'dc' => 'http://purl.org/dc/elements/1.1/'
)
- if (
nil != creator) and (creator
.length > 0)
- roleNode = creator.attr('role')
- if nil !=
roleNode
- role =
roleNode.value
- if
('aut' == role) and (creator.children.length > 0) and (nil != creator.children[0])
- name = creator.c
hildren[0].c
ontent
+ creator
s = opfDoc.css('dc|creator', 'dc' => @@DC_NS_URL
)
+ if (
creators
.length > 0)
+ creator = creators[0]
+ if nil !=
creator
+ role =
creator['opf:role']
+ if
'aut' == role
+ name = creator.content
parts = name.split(' ')
if parts.length > 1
surname = parts[-1]
parts = name.split(' ')
if parts.length > 1
surname = parts[-1]
@@
-210,6
+217,28
@@
class Book
end
end
end
end
+ #---------------------------------------
+ # Title
+
+ titles = opfDoc.css('dc|title', 'dc' => @@DC_NS_URL)
+ if titles.length > 0
+ title = titles[0]
+ if nil != title
+ @title = title.content
+ end
+ end
+
+ #---------------------------------------
+ # Description
+
+ descrNodes = opfDoc.css('dc|description', 'dc' => @@DC_NS_URL)
+ if (descrNodes.length > 0)
+ descrNode = descrNodes[0]
+ if nil != descrNode
+ @description = descrNode.content
+ end
+ end
+
#---------------------------------------
# Other metadata: series, volume, cover
#---------------------------------------
# Other metadata: series, volume, cover
diff --git
a/main.rb
b/main.rb
index 8617ab0146577146d30e6ec73c21c7856ab03a1c..2d7f68b25c33c6bf45dbb0e909e17e3146f53e5b 100644
(file)
--- a/
main.rb
+++ b/
main.rb
@@
-26,6
+26,12
@@
open(outputDir + '/index.html', 'w') do |fd|
fd.puts ' margin: 10px;'
fd.puts ' border 3px solid #73ad21;'
fd.puts '}'
fd.puts ' margin: 10px;'
fd.puts ' border 3px solid #73ad21;'
fd.puts '}'
+ fd.puts 'span.popup { }'
+ fd.puts 'span.popup:hover {text-decoration: none; background: #cfffff; z-index: 6; }'
+ fd.puts 'span.popup span {display: none; position: absolute; '
+ fd.puts ' margin: 4px 0 0 0px; padding: 3px 3px 3px 3px;'
+ fd.puts ' border-style:solid; border-color:black; border-width:1px;}'
+ fd.puts 'span.popup:hover span {display: block; margin: 20px 0 0 0px; background: #ffffaf; z-index:6;}'
fd.puts ' </style>'
fd.puts ' </head>'
fd.puts ' <body>'
fd.puts ' </style>'
fd.puts ' </head>'
fd.puts ' <body>'
@@
-41,7
+47,16
@@
open(outputDir + '/index.html', 'w') do |fd|
end
fd.puts ' <div><table>'
end
fd.puts ' <div><table>'
- fd.puts ' <tr><td><a href="' + book.path + '">' + image + '</a></td><td>' + book.describe() + '</td></tr>'
+ fd.puts ' <tr><td><a href="' + book.path + '">' + image + '</a></td>'
+
+ heading = book.heading()
+ description = book.description()
+ if nil != description
+ fd.puts ' <td><span class="popup">' + heading + '<span><p>' + heading + '</p><p>' + description + '</p></span></span></td></tr>'
+ else
+ fd.puts ' <td>' + heading + '</td></tr>'
+ end
+
fd.puts ' </table></div>'
end
fd.puts ' </table></div>'
end