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