Fix for AZW3 catalogs not properly navigating index points

This commit is contained in:
GRiker 2012-09-14 13:50:48 -06:00
parent bcef201fe3
commit b4e2dc54d1
2 changed files with 59 additions and 38 deletions

View File

@ -360,13 +360,14 @@ class EPUB_MOBI(CatalogPlugin):
recommendations.append(('debug_pipeline', dp,
OptionRecommendation.HIGH))
if opts.fmt == 'mobi' and opts.output_profile and opts.output_profile.startswith("kindle"):
if opts.output_profile and opts.output_profile.startswith("kindle"):
recommendations.append(('output_profile', opts.output_profile,
OptionRecommendation.HIGH))
recommendations.append(('no_inline_toc', True,
OptionRecommendation.HIGH))
recommendations.append(('book_producer',opts.output_profile,
OptionRecommendation.HIGH))
if opts.fmt == 'mobi':
recommendations.append(('no_inline_toc', True,
OptionRecommendation.HIGH))
# Use existing cover or generate new cover
cpath = None

View File

@ -460,8 +460,9 @@ class CatalogBuilder(object):
catalog_resources = P("catalog")
files_to_copy = [('','DefaultCover.jpg'),
('content','stylesheet.css'),
('images','mastheadImage.gif')]
('content','stylesheet.css')]
if self.generate_for_kindle_mobi:
files_to_copy.extend([('images','mastheadImage.gif')])
for file in files_to_copy:
if file[0] == '':
@ -2781,6 +2782,7 @@ class CatalogBuilder(object):
ncx = soup.find('ncx')
navMapTag = Tag(soup, 'navMap')
navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "periodical"
navPointTag['id'] = "title"
navPointTag['playOrder'] = self.play_order
@ -2820,12 +2822,13 @@ class CatalogBuilder(object):
contentTag['src'] = "content/book_%d.html" % int(sort_descriptions_by[0]['id'])
navPointTag.insert(1, contentTag)
if self.generate_for_kindle_mobi:
cmiTag = Tag(soup, '%s' % 'calibre:meta-img')
cmiTag['id'] = "mastheadImage"
cmiTag['src'] = "images/mastheadImage.gif"
navPointTag.insert(2,cmiTag)
navMapTag.insert(0,navPointTag)
navMapTag.insert(0,navPointTag)
ncx.insert(0,navMapTag)
self.ncx_soup = soup
@ -2853,6 +2856,7 @@ class CatalogBuilder(object):
# Add the section navPoint
navPointTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
navPointTag['id'] = "bytitle-ID"
navPointTag['playOrder'] = self.play_order
@ -2865,7 +2869,7 @@ class CatalogBuilder(object):
navPointTag.insert(nptc, navLabelTag)
nptc += 1
contentTag = Tag(ncx_soup,"content")
contentTag['src'] = "content/book_%d.html" % int(self.books_by_title[0]['id'])
contentTag['src'] = "content/book_%d.html" % int(self.books_by_author[0]['id'])
navPointTag.insert(nptc, contentTag)
nptc += 1
@ -2875,6 +2879,7 @@ class CatalogBuilder(object):
for book in sort_descriptions_by:
navPointVolumeTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointVolumeTag['class'] = "article"
navPointVolumeTag['id'] = "book%dID" % int(book['id'])
navPointVolumeTag['playOrder'] = self.play_order
@ -2979,6 +2984,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Series' section ---
navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
navPointTag['id'] = "byseries-ID"
navPointTag['playOrder'] = self.play_order
@ -3035,6 +3041,7 @@ class CatalogBuilder(object):
# Add *article* entries for each populated series title letter
for (i,books) in enumerate(series_by_letter):
navPointByLetterTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByLetterTag['class'] = "article"
navPointByLetterTag['id'] = "%sSeries-ID" % (title_letters[i].upper())
navPointTag['playOrder'] = self.play_order
@ -3102,6 +3109,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Title' section ---
navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
navPointTag['id'] = "byalphatitle-ID"
navPointTag['playOrder'] = self.play_order
@ -3160,6 +3168,7 @@ class CatalogBuilder(object):
# Add *article* entries for each populated title letter
for (i,books) in enumerate(books_by_letter):
navPointByLetterTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByLetterTag['class'] = "article"
navPointByLetterTag['id'] = "%sTitles-ID" % (title_letters[i].upper())
navPointTag['playOrder'] = self.play_order
@ -3225,6 +3234,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Author' *section* ---
navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","")
@ -3275,6 +3285,7 @@ class CatalogBuilder(object):
# master_author_list{}: [0]:author list [1]:Initial letter
for authors_by_letter in master_author_list:
navPointByLetterTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByLetterTag['class'] = "article"
navPointByLetterTag['id'] = "%sauthors-ID" % (authors_by_letter[1])
navPointTag['playOrder'] = self.play_order
@ -3346,6 +3357,7 @@ class CatalogBuilder(object):
# --- Construct the 'Recently Added' *section* ---
navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","")
@ -3390,6 +3402,7 @@ class CatalogBuilder(object):
# master_date_range_list{}: [0]:titles list [1]:datestr
for books_by_date_range in master_date_range_list:
navPointByDateRangeTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByDateRangeTag['class'] = "article"
navPointByDateRangeTag['id'] = "%s-ID" % books_by_date_range[1].replace(' ','')
navPointTag['playOrder'] = self.play_order
@ -3449,6 +3462,7 @@ class CatalogBuilder(object):
for books_by_month in master_month_list:
datestr = strftime(u'%B %Y', books_by_month[1].timetuple())
navPointByMonthTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByMonthTag['class'] = "article"
navPointByMonthTag['id'] = "bda_%s-%s-ID" % (books_by_month[1].year,books_by_month[1].month )
navPointTag['playOrder'] = self.play_order
@ -3524,6 +3538,7 @@ class CatalogBuilder(object):
# --- Construct the 'Recently Read' *section* ---
navPointTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","")
@ -3594,6 +3609,7 @@ class CatalogBuilder(object):
for books_by_day in master_day_list:
datestr = strftime(u'%A, %B %d', books_by_day[1].timetuple())
navPointByDayTag = Tag(soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointByDayTag['class'] = "article"
navPointByDayTag['id'] = "bdr_%s-%s-%sID" % (books_by_day[1].year,
books_by_day[1].month,
@ -3662,6 +3678,7 @@ class CatalogBuilder(object):
# --- Construct the 'Books By Genre' *section* ---
navPointTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointTag['class'] = "section"
file_ID = "%s" % tocTitle.lower()
file_ID = file_ID.replace(" ","")
@ -3684,6 +3701,7 @@ class CatalogBuilder(object):
for genre in self.genres:
# Add an article for each genre
navPointVolumeTag = Tag(ncx_soup, 'navPoint')
if self.generate_for_kindle_mobi:
navPointVolumeTag['class'] = "article"
navPointVolumeTag['id'] = "genre-%s-ID" % genre['tag']
navPointVolumeTag['playOrder'] = self.play_order
@ -3823,6 +3841,7 @@ class CatalogBuilder(object):
manifest.insert(mtc, itemTag)
mtc += 1
if self.generate_for_kindle_mobi:
itemTag = Tag(soup, "item")
itemTag['id'] = 'mastheadimage-image'
itemTag['href'] = "images/mastheadImage.gif"
@ -3914,6 +3933,7 @@ class CatalogBuilder(object):
stc += 1
# Guide
if self.generate_for_kindle_mobi:
referenceTag = Tag(soup, "reference")
referenceTag['type'] = 'masthead'
referenceTag['title'] = 'mastheadimage-image'