Kovid - I have tested the changes on both Windows and Linux (Ubuntu). I don't have any way of testing on OS-X but I'm guessing the changes will work on that as well.
I have attached the modified files (from the latest release) as well as modified NY Times recipes to use the thumbnail image capability.
Folowing are the changes required (line numbers refer to the current files before any changes are applied).
Let me know if you see any issues.
calibre/web/feeds/__init__.py
Insert after line 33:
Code:
self.toc_thumbnail = None
Insert after line 89:
Replace line 92:
Code:
'''%(self.title, self.url, self.author, self.summary[:20]+'...', ('None' if self.toc_thumbnail is None else self.toc_thumbnail), self.localtime.strftime('%a, %d %b, %Y %H:%M'),
calibre/web/feeds/news.py
Insert before line 656:
Code:
def add_toc_thumbnail(self, article, src):
'''
Call this from populate_article_metadata with the src of an img tag you want to
appear as a thumbnail image in the articles list view of the table of contents
(Kindle feature)
'''
article.toc_thumbnail = re.sub(r'^.*feed','feed',src.replace('\\','/'),flags=re.IGNORECASE)
Insert after line 1287:
Code:
idx = a.toc_thumbnail
if not idx:
idx = None
Replace lines 1293-1294:
Code:
parent.add_item('%sindex.html'%adir, None, a.title if a.title else _('Untitled Article'),
play_order=po, author=auth, description=desc, toc_thumbnail=idx)
calibre/ebooks/metadata/toc.py
Replace lines 32-34:
Code:
def __init__(self, href=None, fragment=None, text=None, parent=None, play_order=0,
base_path=os.getcwd(), type='unknown', author=None,
description=None, toc_thumbnail=None):
Insert after line 45:
Code:
self.toc_thumbnail = toc_thumbnail
Replace lines 74-80:
Code:
def add_item(self, href, fragment, text, play_order=None, type='unknown',
author=None, description=None, toc_thumbnail=None):
if play_order is None:
play_order = (self[-1].play_order if len(self) else self.play_order) + 1
self.append(TOC(href=href, fragment=fragment, text=text, parent=self,
base_path=self.base_path, play_order=play_order,
type=type, author=author, description=description, toc_thumbnail=toc_thumbnail))
Insert after line 271:
Code:
idx = getattr(np, 'toc_thumbnail', None)
if idx:
elem.append(C.meta(idx, name='toc_thumbnail'))
calibre/ebooks/oeb/base.py
Replace lines 1619-1651 with:
Code:
class TOC(object):
"""Represents a hierarchical table of contents or navigation tree for
accessing arbitrary semantic sections within an OEB data model book.
Acts as a node within the navigation tree. Provides list-like access to
sub-nodes. Provides the follow node instance data attributes:
:attr:`title`: The title of this navigation node.
:attr:`href`: Book-internal URL referenced by this node.
:attr:`klass`: Optional semantic class referenced by this node.
:attr:`id`: Option unique identifier for this node.
:attr:`author`: Optional author attribution for periodicals <mbp:>
:attr:`description`: Optional description attribute for periodicals <mbp:>
:attr:`toc_thumbnail`: Optional toc thumbnail image
"""
def __init__(self, title=None, href=None, klass=None, id=None,
play_order=None, author=None, description=None, toc_thumbnail=None):
self.title = title
self.href = urlnormalize(href) if href else href
self.klass = klass
self.id = id
self.nodes = []
self.play_order = 0
if play_order is None:
play_order = self.next_play_order()
self.play_order = play_order
self.author = author
self.description = description
self.toc_thumbnail = toc_thumbnail
def add(self, title, href, klass=None, id=None, play_order=0, author=None, description=None, toc_thumbnail=None):
"""Create and return a new sub-node of this node."""
node = TOC(title, href, klass, id, play_order, author, description, toc_thumbnail)
self.nodes.append(node)
return node
calibre/ebooks/oeb/reader.py
Replace lines 374-375:
Code:
indeximageElement = xpath(child,
'descendant::calibre:meta[@name = "toc_thumbnail"]')
if indeximageElement :
toc_thumbnail = indeximageElement[0].text
else :
toc_thumbnail = None
node = toc.add(title, href, id=id, klass=klass,
play_order=po, description=description, author=author,
toc_thumbnail=toc_thumbnail)
calibre/ebooks/mobi/writer2/indexer.py
Replace line 139 with:
Code:
'author_offset': 71,
(Note that the original value of 73 for author_offset is incorrect and this change doesn't relate specifically to the TOC thumbnail image changes.)
Insert after line 756:
Code:
if art.toc_thumbnail is not None:
if art.toc_thumbnail in self.serializer.images:
article.image_index = self.serializer.images[art.toc_thumbnail]