Add include_tocpage:always option.

This commit is contained in:
Jim Miller 2025-02-19 10:10:42 -06:00
parent 80ee0ca9b9
commit 6c70a60cdb
5 changed files with 22 additions and 3 deletions

View file

@ -124,6 +124,10 @@ include_titlepage: true
## include a TOC page before the story text
include_tocpage: true
## When set to 'true', tocpage is only included if there is more than
## one chapter in the story. If set to 'always', tocpage will be
## included even if the story only has one chapter.
#include_tocpage: always
## website encoding(s) In theory, each website reports the character
## encoding they use for each page. In practice, some sites report it
@ -1119,6 +1123,10 @@ zip_output: false
## epub carries the TOC in metadata.
## mobi generated from epub by calibre will have a TOC at the end.
include_tocpage: false
## When set to 'true', tocpage is only included if there is more than
## one chapter in the story. If set to 'always', tocpage will be
## included even if the story only has one chapter.
#include_tocpage: always
## include a Update Log page before the story text. If 'true', the
## log will be updated each time the epub is and all the metadata

View file

@ -190,7 +190,7 @@ def get_valid_set_options():
valdict = {'collect_series':(None,None,boollist),
'include_titlepage':(None,None,boollist),
'include_tocpage':(None,None,boollist),
'include_tocpage':(None,None,boollist+['always']),
'is_adult':(None,None,boollist),
'keep_style_attr':(None,None,boollist),
'keep_title_attr':(None,None,boollist),

View file

@ -124,6 +124,10 @@ include_titlepage: true
## include a TOC page before the story text
include_tocpage: true
## When set to 'true', tocpage is only included if there is more than
## one chapter in the story. If set to 'always', tocpage will be
## included even if the story only has one chapter.
#include_tocpage: always
## website encoding(s) In theory, each website reports the character
## encoding they use for each page. In practice, some sites report it
@ -1109,6 +1113,10 @@ zip_output: false
## epub carries the TOC in metadata.
## mobi generated from epub by calibre will have a TOC at the end.
include_tocpage: false
## When set to 'true', tocpage is only included if there is more than
## one chapter in the story. If set to 'always', tocpage will be
## included even if the story only has one chapter.
#include_tocpage: always
## include a Update Log page before the story text. If 'true', the
## log will be updated each time the epub is and all the metadata

View file

@ -69,6 +69,9 @@ class BaseStoryWriter(Requestable):
def _write(self, out, text):
out.write(ensure_binary(text))
def includeToCPage(self):
return (self.getConfig("include_tocpage")=='always' or (self.story.getChapterCount() > 1 and self.getConfig("include_tocpage"))) and not self.metaonly
def writeTitlePage(self, out, START, ENTRY, END, WIDE_ENTRY=None, NO_TITLE_ENTRY=None):
"""
Write the title page, but only include entries that there's
@ -139,7 +142,7 @@ class BaseStoryWriter(Requestable):
names as Story.metadata, but ENTRY should use index and chapter.
"""
# Only do TOC if there's more than one chapter and it's configured.
if self.story.getChapterCount() > 1 and self.getConfig("include_tocpage") and not self.metaonly :
if self.includeToCPage():
if self.hasConfig("tocpage_start"):
START = string.Template(self.getConfig("tocpage_start"))

View file

@ -597,7 +597,7 @@ div { margin: 0pt; padding: 0pt; }
if self.getConfig("include_titlepage"):
items.append(("title_page","OEBPS/title_page.xhtml","application/xhtml+xml","Title Page"))
itemrefs.append("title_page")
if self.story.getChapterCount() > 1 and self.getConfig("include_tocpage") and not self.metaonly :
if self.includeToCPage():
items.append(("toc_page","OEBPS/toc_page.xhtml","application/xhtml+xml","Table of Contents"))
itemrefs.append("toc_page")