Skip to content

Commit

Permalink
Insert metadata as jacket page: Make the invisible tags used for sear…
Browse files Browse the repository at this point in the history
…ching across books format better, by giving them their own table row.
  • Loading branch information
kovidgoyal committed Oct 23, 2014
1 parent 9b5a4fd commit 9c93a6e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
1 change: 1 addition & 0 deletions resources/jacket/template.xhtml
Expand Up @@ -36,6 +36,7 @@
{tags.alphabetical} -->
<td class="cbj_content">{tags}</td>
</tr>
<tr data-calibre-jacket-searchable-tags="1" style="color:white; display:none"><td colspan="2">{searchable_tags}</td></tr>
</table>
<div class="cbj_footer">{footer}</div>
</div>
Expand Down
20 changes: 0 additions & 20 deletions src/calibre/customize/profiles.py
Expand Up @@ -263,10 +263,6 @@ class OutputProfile(Plugin):
#: Special periodical formatting needed in EPUB
epub_periodical_format = None

@classmethod
def tags_to_string(cls, tags):
from xml.sax.saxutils import escape
return escape(', '.join(tags))

class iPadOutput(OutputProfile):

Expand Down Expand Up @@ -645,11 +641,6 @@ class KindleOutput(OutputProfile):

mobi_ems_per_blockquote = 2.0

@classmethod
def tags_to_string(cls, tags):
return u'%s <br/><span style="color:white">%s</span>' % (', '.join(tags),
'ttt '.join(tags)+'ttt ')

class KindleDXOutput(OutputProfile):

name = 'Kindle DX'
Expand All @@ -667,11 +658,6 @@ class KindleDXOutput(OutputProfile):
ratings_char = u'\u2605'
mobi_ems_per_blockquote = 2.0

@classmethod
def tags_to_string(cls, tags):
return u'%s <br/><span style="color: white">%s</span>' % (', '.join(tags),
'ttt '.join(tags)+'ttt ')

class KindlePaperWhiteOutput(KindleOutput):

name = 'Kindle PaperWhite'
Expand Down Expand Up @@ -706,12 +692,6 @@ class KindleFireOutput(KindleDXOutput):
dpi = 169.0
comic_screen_size = (570, 1016)

@classmethod
def tags_to_string(cls, tags):
# The idiotic fire doesn't obey the color:white directive
from xml.sax.saxutils import escape
return escape(', '.join(tags))

class IlliadOutput(OutputProfile):

name = 'Illiad'
Expand Down
4 changes: 2 additions & 2 deletions src/calibre/ebooks/mobi/mobiml.py
Expand Up @@ -310,8 +310,8 @@ def mobimlize_elem(self, elem, stylizer, bstate, istates,
return
style = stylizer.style(elem)
# <mbp:frame-set/> does not exist lalalala
if style['display'] in ('none', 'oeb-page-head', 'oeb-page-foot') \
or style['visibility'] == 'hidden':
if ((style['display'] in ('none', 'oeb-page-head', 'oeb-page-foot') or style['visibility'] == 'hidden') and
elem.get('data-calibre-jacket-searchable-tags', None) != '1'):
id_ = elem.get('id', None)
if id_:
# Keep anchors so people can use display:none
Expand Down
10 changes: 6 additions & 4 deletions src/calibre/ebooks/oeb/transforms/jacket.py
Expand Up @@ -159,9 +159,10 @@ def __new__(self, series, series_index):
class Tags(unicode):

def __new__(self, tags, output_profile):
tags = tags or ()
t = unicode.__new__(self, output_profile.tags_to_string(tags))
t.alphabetical = output_profile.tags_to_string(sorted(tags, key=sort_key))
tags = [escape(x) for x in tags or ()]
t = unicode.__new__(self, ', '.join(tags))
t.alphabetical = ', '.join(sorted(tags, key=sort_key))
t.tags_list = tags
return t

def render_jacket(mi, output_profile,
Expand Down Expand Up @@ -217,7 +218,8 @@ def generate_html(comments):
rating_label=_('Rating'), rating=rating,
tags_label=_('Tags'), tags=tags,
comments=comments,
footer=''
footer='',
searchable_tags=' '.join(escape(t)+'ttt' for t in tags.tags_list),
)
for key in mi.custom_field_keys():
try:
Expand Down

0 comments on commit 9c93a6e

Please sign in to comment.