mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GwR Description template fixes
This commit is contained in:
parent
32a2993c76
commit
71f90fc6bd
@ -13,11 +13,11 @@
|
|||||||
<p class="formats">{formats}</p>
|
<p class="formats">{formats}</p>
|
||||||
<table width="100%" border="0">
|
<table width="100%" border="0">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="thumbnail" rowspan="7"></td>
|
<td class="thumbnail" rowspan="7">{thumb}</td>
|
||||||
<td></td>
|
<td class="empty"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td class="empty"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="publisher">{publisher}</td>
|
<td class="publisher">{publisher}</td>
|
||||||
@ -36,6 +36,6 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<hr class="description_divider" />
|
<hr class="description_divider" />
|
||||||
<div class="description"></div>
|
<div class="description">{comments}</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -14,6 +14,7 @@ from calibre.constants import preferred_encoding, DEBUG
|
|||||||
from calibre.customize import CatalogPlugin
|
from calibre.customize import CatalogPlugin
|
||||||
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
from calibre.customize.conversion import OptionRecommendation, DummyReporter
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString
|
from calibre.ebooks.BeautifulSoup import BeautifulSoup, BeautifulStoneSoup, Tag, NavigableString
|
||||||
|
from calibre.ebooks.chardet import substitute_entites
|
||||||
from calibre.ebooks.oeb.base import RECOVER_PARSER, XHTML_NS
|
from calibre.ebooks.oeb.base import RECOVER_PARSER, XHTML_NS
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre.utils.config import config_dir
|
from calibre.utils.config import config_dir
|
||||||
@ -4284,12 +4285,11 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
'''
|
'''
|
||||||
Generate description header from template
|
Generate description header from template
|
||||||
'''
|
'''
|
||||||
NBSP = ' '
|
|
||||||
MIDDOT = '·'
|
|
||||||
def generate_html():
|
def generate_html():
|
||||||
args = dict(
|
args = dict(
|
||||||
author=author,
|
author=author,
|
||||||
author_prefix=author_prefix,
|
author_prefix=author_prefix,
|
||||||
|
comments=comments,
|
||||||
css=css,
|
css=css,
|
||||||
formats=formats,
|
formats=formats,
|
||||||
genres=genres,
|
genres=genres,
|
||||||
@ -4302,6 +4302,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
rating=rating,
|
rating=rating,
|
||||||
series=series,
|
series=series,
|
||||||
series_index=series_index,
|
series_index=series_index,
|
||||||
|
thumb=thumb,
|
||||||
title=title,
|
title=title,
|
||||||
title_str=title_str,
|
title_str=title_str,
|
||||||
xmlns=XHTML_NS,
|
xmlns=XHTML_NS,
|
||||||
@ -4309,9 +4310,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
|
|
||||||
generated_html = P('catalog/template.xhtml',
|
generated_html = P('catalog/template.xhtml',
|
||||||
data=True).decode('utf-8').format(**args)
|
data=True).decode('utf-8').format(**args)
|
||||||
|
generated_html = substitute_entites(generated_html)
|
||||||
soup = BeautifulSoup(generated_html)
|
return BeautifulSoup(generated_html)
|
||||||
return soup.renderContents(None)
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
print "title metadata:\n%s" % ', '.join(sorted(book.keys()))
|
print "title metadata:\n%s" % ', '.join(sorted(book.keys()))
|
||||||
@ -4365,7 +4365,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
genresTag.insert(gtc, aTag)
|
genresTag.insert(gtc, aTag)
|
||||||
gtc += 1
|
gtc += 1
|
||||||
if i < len(book['tags'])-1:
|
if i < len(book['tags'])-1:
|
||||||
genresTag.insert(gtc, NavigableString(' %s ' % MIDDOT))
|
genresTag.insert(gtc, NavigableString(' · '))
|
||||||
gtc += 1
|
gtc += 1
|
||||||
genres = genresTag.renderContents()
|
genres = genresTag.renderContents()
|
||||||
|
|
||||||
@ -4374,26 +4374,22 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
if 'formats' in book:
|
if 'formats' in book:
|
||||||
for format in sorted(book['formats']):
|
for format in sorted(book['formats']):
|
||||||
formats.append(format.rpartition('.')[2].upper())
|
formats.append(format.rpartition('.')[2].upper())
|
||||||
formats = ' %s ' % MIDDOT.join(formats)
|
formats = ' · '.join(formats)
|
||||||
|
|
||||||
pubdate = book['date']
|
pubdate = book['date']
|
||||||
pubmonth, pubyear = pubdate.split(' ')
|
pubmonth, pubyear = pubdate.split(' ')
|
||||||
|
|
||||||
'''
|
|
||||||
# Thumb
|
# Thumb
|
||||||
# This doesn't make it through the etree.fromstring parsing
|
_soup = BeautifulSoup('<html>',selfClosingTags=['img'])
|
||||||
_soup = BeautifulSoup('')
|
thumb = Tag(_soup,"img")
|
||||||
imgTag = Tag(_soup,"img")
|
|
||||||
if 'cover' in book:
|
if 'cover' in book:
|
||||||
imgTag['src'] = "../images/thumbnail_%d.jpg" % int(book['id'])
|
thumb['src'] = "../images/thumbnail_%d.jpg" % int(book['id'])
|
||||||
else:
|
else:
|
||||||
imgTag['src'] = "../images/thumbnail_default.jpg"
|
thumb['src'] = "../images/thumbnail_default.jpg"
|
||||||
imgTag['alt'] = "cover thumbnail"
|
thumb['alt'] = "cover thumbnail"
|
||||||
thumb = imgTag.renderContents()
|
|
||||||
'''
|
|
||||||
|
|
||||||
# Publisher
|
# Publisher
|
||||||
publisher = ''
|
publisher = ' '
|
||||||
if 'publisher' in book:
|
if 'publisher' in book:
|
||||||
publisher = book['publisher']
|
publisher = book['publisher']
|
||||||
|
|
||||||
@ -4412,10 +4408,14 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
note_source = book['notes']['source']
|
note_source = book['notes']['source']
|
||||||
note_content = book['notes']['content']
|
note_content = book['notes']['content']
|
||||||
|
|
||||||
|
# Comments
|
||||||
|
comments = ''
|
||||||
|
if 'description' in book and book['description'] > '':
|
||||||
|
comments = book['description']
|
||||||
|
|
||||||
|
|
||||||
# >>>> Populate the template <<<<
|
# >>>> Populate the template <<<<
|
||||||
root = etree.fromstring(generate_html(), parser=RECOVER_PARSER)
|
soup = generate_html()
|
||||||
header = etree.tostring(root, pretty_print=True, encoding='utf-8')
|
|
||||||
soup = BeautifulSoup(header, selfClosingTags=['mbp:pagebreak'])
|
|
||||||
|
|
||||||
|
|
||||||
# >>>> Post-process the template <<<<
|
# >>>> Post-process the template <<<<
|
||||||
@ -4441,6 +4441,10 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor",
|
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor",
|
||||||
self.generateAuthorAnchor(book['author']))
|
self.generateAuthorAnchor(book['author']))
|
||||||
|
|
||||||
|
if publisher == ' ':
|
||||||
|
publisherTag = body.find('td', attrs={'class':'publisher'})
|
||||||
|
publisherTag.contents[0].replaceWith(' ')
|
||||||
|
|
||||||
if not genres:
|
if not genres:
|
||||||
genresTag = body.find('p',attrs={'class':'genres'})
|
genresTag = body.find('p',attrs={'class':'genres'})
|
||||||
genresTag.extract()
|
genresTag.extract()
|
||||||
@ -4451,34 +4455,13 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
|
|
||||||
if note_content == '':
|
if note_content == '':
|
||||||
tdTag = body.find('td', attrs={'class':'notes'})
|
tdTag = body.find('td', attrs={'class':'notes'})
|
||||||
tdTag.contents[0].replaceWith(NBSP)
|
tdTag.contents[0].replaceWith(' ')
|
||||||
|
|
||||||
# Cover thumb
|
emptyTags = body.findAll('td', attrs={'class':'empty'})
|
||||||
tdTag = body.find('td', attrs={'class':'thumbnail'})
|
for mt in emptyTags:
|
||||||
imgTag = Tag(soup,"img")
|
newEmptyTag = Tag(BeautifulSoup(),'td')
|
||||||
if 'cover' in book:
|
newEmptyTag.insert(0,NavigableString(' '))
|
||||||
imgTag['src'] = "../images/thumbnail_%d.jpg" % int(book['id'])
|
mt.replaceWith(newEmptyTag)
|
||||||
else:
|
|
||||||
imgTag['src'] = "../images/thumbnail_default.jpg"
|
|
||||||
imgTag['alt'] = "cover thumbnail"
|
|
||||||
tdTag.insert(0,imgTag)
|
|
||||||
|
|
||||||
'''
|
|
||||||
# Rating
|
|
||||||
stars = int(book['rating']) / 2
|
|
||||||
rating = ''
|
|
||||||
if stars:
|
|
||||||
star_string = self.FULL_RATING_SYMBOL * stars
|
|
||||||
empty_stars = self.EMPTY_RATING_SYMBOL * (5 - stars)
|
|
||||||
rating = '%s%s <br/>' % (star_string,empty_stars)
|
|
||||||
ratingTag = body.find('td',attrs={'class':'rating'})
|
|
||||||
ratingTag.insert(0,NavigableString(rating))
|
|
||||||
'''
|
|
||||||
|
|
||||||
# The Blurb
|
|
||||||
if 'description' in book and book['description'] > '':
|
|
||||||
blurbTag = body.find(attrs={'class':'description'})
|
|
||||||
blurbTag.insert(0,NavigableString(book['description']))
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
print soup.prettify()
|
print soup.prettify()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user