diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index 87fefda5..2bd0f29a 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -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 diff --git a/fanficfare/configurable.py b/fanficfare/configurable.py index 21357eb6..483fc5a4 100644 --- a/fanficfare/configurable.py +++ b/fanficfare/configurable.py @@ -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), diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index cbde0deb..a7dd2530 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -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 diff --git a/fanficfare/writers/base_writer.py b/fanficfare/writers/base_writer.py index d8776a00..29c3ea54 100644 --- a/fanficfare/writers/base_writer.py +++ b/fanficfare/writers/base_writer.py @@ -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")) diff --git a/fanficfare/writers/writer_epub.py b/fanficfare/writers/writer_epub.py index 1d756fae..db99a9fc 100644 --- a/fanficfare/writers/writer_epub.py +++ b/fanficfare/writers/writer_epub.py @@ -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")