mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
GwR revisions to catalog, making 'By Authors' optional
This commit is contained in:
parent
dda48835c5
commit
add04ff930
@ -35,7 +35,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Sections to include in catalog. All catalogs include 'Books by Author'.</string>
|
||||
<string>Sections to include in catalog.</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Included sections</string>
|
||||
@ -79,13 +79,13 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="generate_authors">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Books by Author</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -29,7 +29,6 @@ FIELDS = ['all', 'author_sort', 'authors', 'comments',
|
||||
'series_index', 'series', 'size', 'tags', 'timestamp', 'title',
|
||||
'uuid']
|
||||
|
||||
|
||||
#Allowed fields for template
|
||||
TEMPLATE_ALLOWED_FIELDS = [ 'author_sort', 'authors', 'id', 'isbn', 'pubdate',
|
||||
'publisher', 'series_index', 'series', 'tags', 'timestamp', 'title', 'uuid' ]
|
||||
@ -605,43 +604,42 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
"Default: '%default'\n"
|
||||
"Applies to: ePub, MOBI output formats")),
|
||||
Option('--generate-authors',
|
||||
default=True,
|
||||
default=False,
|
||||
dest='generate_authors',
|
||||
action = 'store_true',
|
||||
help=_("Include 'Authors' section in catalog."
|
||||
"This switch is ignored - Books By Author section is always generated."
|
||||
help=_("Include 'Authors' section in catalog.\n"
|
||||
"Default: '%default'\n"
|
||||
"Applies to: ePub, MOBI output formats")),
|
||||
Option('--generate-descriptions',
|
||||
default=True,
|
||||
default=False,
|
||||
dest='generate_descriptions',
|
||||
action = 'store_true',
|
||||
help=_("Include book descriptions in catalog.\n"
|
||||
help=_("Include 'Descriptions' section in catalog.\n"
|
||||
"Default: '%default'\n"
|
||||
"Applies to: ePub, MOBI output formats")),
|
||||
Option('--generate-genres',
|
||||
default=True,
|
||||
default=False,
|
||||
dest='generate_genres',
|
||||
action = 'store_true',
|
||||
help=_("Include 'Genres' section in catalog.\n"
|
||||
"Default: '%default'\n"
|
||||
"Applies to: ePub, MOBI output formats")),
|
||||
Option('--generate-titles',
|
||||
default=True,
|
||||
default=False,
|
||||
dest='generate_titles',
|
||||
action = 'store_true',
|
||||
help=_("Include 'Titles' section in catalog.\n"
|
||||
"Default: '%default'\n"
|
||||
"Applies to: ePub, MOBI output formats")),
|
||||
Option('--generate-series',
|
||||
default=True,
|
||||
default=False,
|
||||
dest='generate_series',
|
||||
action = 'store_true',
|
||||
help=_("Include 'Series' section in catalog.\n"
|
||||
"Default: '%default'\n"
|
||||
"Applies to: ePub, MOBI output formats")),
|
||||
Option('--generate-recently-added',
|
||||
default=True,
|
||||
default=False,
|
||||
dest='generate_recently_added',
|
||||
action = 'store_true',
|
||||
help=_("Include 'Recently Added' section in catalog.\n"
|
||||
@ -976,7 +974,7 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
self.__thumbWidth = 0
|
||||
self.__thumbHeight = 0
|
||||
self.__title = opts.catalog_title
|
||||
self.__totalSteps = 8.0
|
||||
self.__totalSteps = 6.0
|
||||
self.__useSeriesPrefixInTitlesSection = False
|
||||
self.__verbose = opts.verbose
|
||||
|
||||
@ -1014,17 +1012,21 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
(self.__archive_path, float(cached_thumb_width)))
|
||||
|
||||
# Tweak build steps based on optional sections: 1 call for HTML, 1 for NCX
|
||||
incremental_jobs = 0
|
||||
if self.opts.generate_authors:
|
||||
incremental_jobs += 2
|
||||
if self.opts.generate_titles:
|
||||
self.__totalSteps += 2
|
||||
incremental_jobs += 2
|
||||
if self.opts.generate_recently_added:
|
||||
self.__totalSteps += 2
|
||||
incremental_jobs += 2
|
||||
if self.generateRecentlyRead:
|
||||
self.__totalSteps += 2
|
||||
incremental_jobs += 2
|
||||
if self.opts.generate_series:
|
||||
self.__totalSteps += 2
|
||||
incremental_jobs += 2
|
||||
if self.opts.generate_descriptions:
|
||||
# +1 thumbs
|
||||
self.__totalSteps += 3
|
||||
incremental_jobs += 3
|
||||
self.__totalSteps += incremental_jobs
|
||||
|
||||
# Load section list templates
|
||||
templates = []
|
||||
@ -1358,6 +1360,7 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
if self.opts.generate_descriptions:
|
||||
self.generateThumbnails()
|
||||
self.generateHTMLDescriptions()
|
||||
if self.opts.generate_authors:
|
||||
self.generateHTMLByAuthor()
|
||||
if self.opts.generate_titles:
|
||||
self.generateHTMLByTitle()
|
||||
@ -1365,6 +1368,13 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
self.generateHTMLBySeries()
|
||||
if self.opts.generate_genres:
|
||||
self.generateHTMLByTags()
|
||||
# If this is the only Section, and there are no genres, bail
|
||||
if self.opts.section_list == ['Genres'] and not self.genres:
|
||||
error_msg = _("No Genres found to catalog.\nCheck 'Excluded genres'\nin E-book options.\n")
|
||||
self.opts.log.error(error_msg)
|
||||
self.error.append(_('No books available to catalog'))
|
||||
self.error.append(error_msg)
|
||||
return False
|
||||
if self.opts.generate_recently_added:
|
||||
self.generateHTMLByDateAdded()
|
||||
if self.generateRecentlyRead:
|
||||
@ -1372,6 +1382,7 @@ class EPUB_MOBI(CatalogPlugin):
|
||||
|
||||
self.generateOPF()
|
||||
self.generateNCXHeader()
|
||||
if self.opts.generate_authors:
|
||||
self.generateNCXByAuthor("Authors")
|
||||
if self.opts.generate_titles:
|
||||
self.generateNCXByTitle("Titles")
|
||||
@ -1879,6 +1890,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
# Link to author
|
||||
emTag = Tag(soup, "em")
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generateAuthorAnchor(book['author']))
|
||||
aTag.insert(0, NavigableString(book['author']))
|
||||
emTag.insert(0,aTag)
|
||||
@ -2149,6 +2161,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
pAuthorTag = Tag(soup, "p")
|
||||
pAuthorTag['class'] = "author_index"
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['name'] = "%s" % self.generateAuthorAnchor(current_author)
|
||||
aTag.insert(0,NavigableString(current_author))
|
||||
pAuthorTag.insert(0,aTag)
|
||||
@ -2276,6 +2289,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
# Link to author
|
||||
emTag = Tag(soup, "em")
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generateAuthorAnchor(new_entry['author']))
|
||||
aTag.insert(0, NavigableString(new_entry['author']))
|
||||
emTag.insert(0,aTag)
|
||||
@ -2425,6 +2439,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
# Link to author
|
||||
emTag = Tag(soup, "em")
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generateAuthorAnchor(new_entry['author']))
|
||||
aTag.insert(0, NavigableString(new_entry['author']))
|
||||
emTag.insert(0,aTag)
|
||||
@ -2473,6 +2488,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
# Link to author
|
||||
emTag = Tag(soup, "em")
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generateAuthorAnchor(new_entry['author']))
|
||||
aTag.insert(0, NavigableString(new_entry['author']))
|
||||
emTag.insert(0,aTag)
|
||||
@ -2692,6 +2708,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
|
||||
# Link to author
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor",
|
||||
self.generateAuthorAnchor(escape(' & '.join(book['authors']))))
|
||||
aTag.insert(0, NavigableString(' & '.join(book['authors'])))
|
||||
@ -3074,10 +3091,34 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
textTag.insert(0, NavigableString(self.title))
|
||||
navLabelTag.insert(0, textTag)
|
||||
navPointTag.insert(0, navLabelTag)
|
||||
|
||||
if self.opts.generate_authors:
|
||||
contentTag = Tag(soup, 'content')
|
||||
#contentTag['src'] = "content/book_%d.html" % int(self.booksByTitle[0]['id'])
|
||||
contentTag['src'] = "content/ByAlphaAuthor.html"
|
||||
navPointTag.insert(1, contentTag)
|
||||
elif self.opts.generate_titles:
|
||||
contentTag = Tag(soup, 'content')
|
||||
contentTag['src'] = "content/ByAlphaTitle.html"
|
||||
navPointTag.insert(1, contentTag)
|
||||
elif self.opts.generate_series:
|
||||
contentTag = Tag(soup, 'content')
|
||||
contentTag['src'] = "content/BySeries.html"
|
||||
navPointTag.insert(1, contentTag)
|
||||
elif self.opts.generate_genres:
|
||||
contentTag = Tag(soup, 'content')
|
||||
contentTag['src'] = "content/ByGenres.html"
|
||||
navPointTag.insert(1, contentTag)
|
||||
elif self.opts.generate_recently_added:
|
||||
contentTag = Tag(soup, 'content')
|
||||
contentTag['src'] = "content/ByDateAdded.html"
|
||||
navPointTag.insert(1, contentTag)
|
||||
else:
|
||||
sort_descriptions_by = self.booksByAuthor if self.opts.sort_descriptions_by_author \
|
||||
else self.booksByTitle
|
||||
contentTag = Tag(soup, 'content')
|
||||
contentTag['src'] = "content/book_%d.html" % int(sort_descriptions_by[0]['id'])
|
||||
navPointTag.insert(1, contentTag)
|
||||
|
||||
cmiTag = Tag(soup, '%s' % 'calibre:meta-img')
|
||||
cmiTag['name'] = "mastheadImage"
|
||||
cmiTag['src'] = "images/mastheadImage.gif"
|
||||
@ -4140,6 +4181,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
pAuthorTag = Tag(soup, "p")
|
||||
pAuthorTag['class'] = "author_index"
|
||||
aTag = Tag(soup, "a")
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor", self.generateAuthorAnchor(book['author']))
|
||||
aTag.insert(0, book['author'])
|
||||
pAuthorTag.insert(0,aTag)
|
||||
@ -4371,6 +4413,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
|
||||
# Insert the author link (always)
|
||||
aTag = body.find('a', attrs={'class':'author'})
|
||||
if self.opts.generate_authors:
|
||||
aTag['href'] = "%s.html#%s" % ("ByAlphaAuthor",
|
||||
self.generateAuthorAnchor(book['author']))
|
||||
|
||||
@ -4860,6 +4903,8 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
|
||||
opts.basename = "Catalog"
|
||||
opts.cli_environment = not hasattr(opts,'sync')
|
||||
|
||||
# Hard-wired to always sort descriptions by author, with series after non-series
|
||||
opts.sort_descriptions_by_author = True
|
||||
|
||||
build_log = []
|
||||
@ -4898,14 +4943,13 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
if opts_dict['ids']:
|
||||
build_log.append(" book count: %d" % len(opts_dict['ids']))
|
||||
|
||||
'''
|
||||
sections_list = []
|
||||
if opts.generate_authors:
|
||||
sections_list.append('Authors')
|
||||
'''
|
||||
sections_list = ['Authors']
|
||||
if opts.generate_titles:
|
||||
sections_list.append('Titles')
|
||||
if opts.generate_series:
|
||||
sections_list.append('Series')
|
||||
if opts.generate_genres:
|
||||
sections_list.append('Genres')
|
||||
if opts.generate_recently_added:
|
||||
@ -4913,7 +4957,18 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
if opts.generate_descriptions:
|
||||
sections_list.append('Descriptions')
|
||||
|
||||
if not sections_list:
|
||||
opts.log.warn('\n*** No enabled Sections, terminating catalog generation ***')
|
||||
opts.log.warn('When invoking from the CLI, add one or more of the Section switches:\n'
|
||||
' --generate-authors\n'
|
||||
' --generate-titles\n'
|
||||
' --generate-series\n'
|
||||
' --generate-genres\n'
|
||||
' --generate-recently-added\n'
|
||||
' --generate-descriptions')
|
||||
return ["No Included Sections","No enabled Sections.\nCheck E-book options tab\n'Included sections'\n"]
|
||||
build_log.append(u" Sections: %s" % ', '.join(sections_list))
|
||||
opts.section_list = sections_list
|
||||
|
||||
# Limit thumb_width to 1.0" - 2.0"
|
||||
try:
|
||||
@ -4948,6 +5003,7 @@ then rebuild the catalog.\n''').format(author[0],author[1],current_author[1])
|
||||
|
||||
# Launch the Catalog builder
|
||||
catalog = self.CatalogBuilder(db, opts, self, report_progress=notification)
|
||||
|
||||
if opts.verbose:
|
||||
log.info(" Begin catalog source generation")
|
||||
catalog.createDirectoryStructure()
|
||||
|
Loading…
x
Reference in New Issue
Block a user