mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Insert metadata: Allow showing identifiers such as ISBN in the jacket page template
This commit is contained in:
parent
3f8403ca84
commit
e19e08ecc4
@ -39,6 +39,13 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr data-calibre-jacket-searchable-tags="1" style="color:white; display:none"><td colspan="2">{searchable_tags}</td></tr>
|
<tr data-calibre-jacket-searchable-tags="1" style="color:white; display:none"><td colspan="2">{searchable_tags}</td></tr>
|
||||||
</table>
|
</table>
|
||||||
|
<!--
|
||||||
|
If you want to insert the identifiers you can do so either as a
|
||||||
|
comma separated list of links, just like they are displayed in
|
||||||
|
the Book details panel, or as individual entries, for example::
|
||||||
|
<div style="display: {display.identifiers}">{identifiers.links}</div>
|
||||||
|
<div style="display: {identifiers.display.isbn}">{identifiers.isbn}</div>
|
||||||
|
-->
|
||||||
<div class="cbj_footer">{footer}</div>
|
<div class="cbj_footer">{footer}</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="cbj_kindle_banner_hr" />
|
<hr class="cbj_kindle_banner_hr" />
|
||||||
|
@ -6,19 +6,24 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import sys, os, re
|
import os
|
||||||
from xml.sax.saxutils import escape
|
import re
|
||||||
|
import sys
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
|
from xml.sax.saxutils import escape
|
||||||
|
|
||||||
from calibre import guess_type, strftime
|
from calibre import guess_type, prepare_string_for_xml, strftime
|
||||||
from calibre.constants import iswindows
|
from calibre.constants import iswindows
|
||||||
from calibre.ebooks.oeb.base import XPath, XHTML_NS, XHTML, xml2text, urldefrag, urlnormalize
|
|
||||||
from calibre.library.comments import comments_to_html, markdown
|
|
||||||
from calibre.utils.date import is_date_undefined, as_local_time
|
|
||||||
from calibre.utils.icu import sort_key
|
|
||||||
from calibre.ebooks.chardet import strip_encoding_declarations
|
from calibre.ebooks.chardet import strip_encoding_declarations
|
||||||
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
from calibre.ebooks.metadata import fmt_sidx, rating_to_stars
|
||||||
from polyglot.builtins import unicode_type, map
|
from calibre.ebooks.metadata.sources.identify import urls_from_identifiers
|
||||||
|
from calibre.ebooks.oeb.base import (
|
||||||
|
XHTML, XHTML_NS, XPath, urldefrag, urlnormalize, xml2text
|
||||||
|
)
|
||||||
|
from calibre.library.comments import comments_to_html, markdown
|
||||||
|
from calibre.utils.date import as_local_time, is_date_undefined
|
||||||
|
from calibre.utils.icu import sort_key
|
||||||
|
from polyglot.builtins import map, unicode_type
|
||||||
|
|
||||||
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
JACKET_XPATH = '//h:meta[@name="calibre-content" and @content="jacket"]'
|
||||||
|
|
||||||
@ -235,6 +240,24 @@ class Attributes:
|
|||||||
return 'none'
|
return 'none'
|
||||||
|
|
||||||
|
|
||||||
|
class Identifiers:
|
||||||
|
|
||||||
|
def __init__(self, idents):
|
||||||
|
self.identifiers = idents or {}
|
||||||
|
self.display = Attributes()
|
||||||
|
for k in self.identifiers:
|
||||||
|
setattr(self.display, k, 'initial')
|
||||||
|
links = []
|
||||||
|
for x in urls_from_identifiers(self.identifiers):
|
||||||
|
name, id_typ, id_val, url = (prepare_string_for_xml(e, True) for e in x)
|
||||||
|
links.append(f'<a href="{url}" title="{id_typ}:{id_val}">{name}</a>')
|
||||||
|
self.links = ', '.join(links)
|
||||||
|
self.display.links = 'initial' if self.links else 'none'
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return self.identifiers.get(name, '')
|
||||||
|
|
||||||
|
|
||||||
def render_jacket(mi, output_profile,
|
def render_jacket(mi, output_profile,
|
||||||
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
|
alt_title=_('Unknown'), alt_tags=[], alt_comments='',
|
||||||
alt_publisher='', rescale_fonts=False, alt_authors=None):
|
alt_publisher='', rescale_fonts=False, alt_authors=None):
|
||||||
@ -291,6 +314,7 @@ def render_jacket(mi, output_profile,
|
|||||||
display = Attributes()
|
display = Attributes()
|
||||||
args = dict(xmlns=XHTML_NS,
|
args = dict(xmlns=XHTML_NS,
|
||||||
title_str=title_str,
|
title_str=title_str,
|
||||||
|
identifiers=Identifiers(mi.identifiers),
|
||||||
css=css,
|
css=css,
|
||||||
title=title,
|
title=title,
|
||||||
author=author,
|
author=author,
|
||||||
@ -352,6 +376,8 @@ def render_jacket(mi, output_profile,
|
|||||||
for k, v in has_data.items():
|
for k, v in has_data.items():
|
||||||
setattr(display, k, 'initial' if v else 'none')
|
setattr(display, k, 'initial' if v else 'none')
|
||||||
display.title = 'initial'
|
display.title = 'initial'
|
||||||
|
if mi.identifiers:
|
||||||
|
display.identifiers = 'initial'
|
||||||
|
|
||||||
formatter = SafeFormatter()
|
formatter = SafeFormatter()
|
||||||
generated_html = formatter.format(template, **args)
|
generated_html = formatter.format(template, **args)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user