diff --git a/se/data/templates/kindle.css b/se/data/templates/kindle.css index fcfb9d03..3f3b05f8 100644 --- a/se/data/templates/kindle.css +++ b/se/data/templates/kindle.css @@ -1,4 +1,5 @@ -/* kindle compatibility CSS */ +/* Kindle compatibility CSS */ + .endnotes p[id], .footnotes p[id]{ margin-top: 1em; diff --git a/se/data/templates/kobo.css b/se/data/templates/kobo.css new file mode 100644 index 00000000..291df720 --- /dev/null +++ b/se/data/templates/kobo.css @@ -0,0 +1,8 @@ +/* Kobo compatibility CSS */ + +section[epub|type~="titlepage"] h1, +section[epub|type~="titlepage"] p, +section[epub|type~="colophon"] h2, +section[epub|type~="imprint"] h2{ + font-size: 0; /* Required for Kobo not to add an extra page to the title */ +} diff --git a/se/data/templates/se-kindle.css b/se/data/templates/se-kindle.css new file mode 100644 index 00000000..7f3cabf7 --- /dev/null +++ b/se/data/templates/se-kindle.css @@ -0,0 +1,8 @@ +/* Kindle compatibility CSS */ + +section[epub|type~="titlepage"] h1, +section[epub|type~="titlepage"] p, +section[epub|type~="colophon"] h2, +section[epub|type~="imprint"] h2{ + position: absolute; +} diff --git a/se/data/templates/se-kobo.css b/se/data/templates/se-kobo.css new file mode 100644 index 00000000..291df720 --- /dev/null +++ b/se/data/templates/se-kobo.css @@ -0,0 +1,8 @@ +/* Kobo compatibility CSS */ + +section[epub|type~="titlepage"] h1, +section[epub|type~="titlepage"] p, +section[epub|type~="colophon"] h2, +section[epub|type~="imprint"] h2{ + font-size: 0; /* Required for Kobo not to add an extra page to the title */ +} diff --git a/se/data/templates/se.css b/se/data/templates/se.css index e8f8985a..8fea497f 100644 --- a/se/data/templates/se.css +++ b/se/data/templates/se.css @@ -10,9 +10,7 @@ section[epub|type~="titlepage"] h1, section[epub|type~="titlepage"] p, section[epub|type~="colophon"] h2, section[epub|type~="imprint"] h2{ - font-size: 0; /* Required for Kobo not to add an extra page to the title */ left: -999em; - position: absolute; /* Required for Kindle */ } section[epub|type~="titlepage"] img{ diff --git a/se/se_epub_build.py b/se/se_epub_build.py index 6ec74efa..0da8d4e1 100644 --- a/se/se_epub_build.py +++ b/se/se_epub_build.py @@ -226,9 +226,9 @@ def build(self, run_epubcheck: bool, check_only: bool, build_kobo: bool, build_k if not self.metadata_dom.xpath("//dc:identifier[starts-with(., 'url:https://standardebooks.org')]"): compatibility_css_filename = "compatibility-white-label.css" - with open(work_compatible_epub_dir / "epub" / "css" / "core.css", "a", encoding="utf-8") as core_css_file: + with open(work_compatible_epub_dir / "epub" / "css" / "core.css", "a", encoding="utf-8") as css_file: with importlib.resources.files("se.data.templates").joinpath(compatibility_css_filename).open("r", encoding="utf-8") as compatibility_css_file: - core_css_file.write("\n" + compatibility_css_file.read()) + css_file.write("\n\n" + compatibility_css_file.read()) # Simplify CSS and tags total_css = "" @@ -678,6 +678,10 @@ def build(self, run_epubcheck: bool, check_only: bool, build_kobo: bool, build_k work_kepub_dir = Path(work_dir / (work_compatible_epub_dir.name + ".kepub")) shutil.copytree(work_compatible_epub_dir, str(work_kepub_dir), dirs_exist_ok=True) + with open(work_kepub_dir / "epub" / "css" / "se.css", "a", encoding="utf-8") as css_file: + with importlib.resources.files("se.data.templates").joinpath("se-kobo.css").open("r", encoding="utf-8") as compatibility_css_file: + css_file.write("\n\n" + compatibility_css_file.read()) + for file_path in work_kepub_dir.glob("**/*"): # Add a note to the metadata file indicating this is a transform build if file_path.name == self.metadata_file_path.name: @@ -1299,6 +1303,10 @@ def build(self, run_epubcheck: bool, check_only: bool, build_kobo: bool, build_k return if build_kindle: + with open(work_compatible_epub_dir / "epub" / "css" / "se.css", "a", encoding="utf-8") as css_file: + with importlib.resources.files("se.data.templates").joinpath("se-kindle.css").open("r", encoding="utf-8") as compatibility_css_file: + css_file.write("\n\n" + compatibility_css_file.read()) + # Kindle doesn't go more than 2 levels deep for ToC, so flatten it here. with open(work_compatible_epub_dir / "epub" / toc_filename, "r+", encoding="utf-8") as file: dom = se.easy_xml.EasyXmlTree(file.read()) @@ -1406,7 +1414,7 @@ def build(self, run_epubcheck: bool, check_only: bool, build_kobo: bool, build_k # Include compatibility CSS with open(work_compatible_epub_dir / "epub" / "css" / "core.css", "a", encoding="utf-8") as core_css_file: with importlib.resources.files("se.data.templates").joinpath("kindle.css").open("r", encoding="utf-8") as compatibility_css_file: - core_css_file.write("\n" + compatibility_css_file.read()) + core_css_file.write("\n\n" + compatibility_css_file.read()) # Build an epub file we can send to Calibre se.epub.write_epub(work_compatible_epub_dir, work_dir / compatible_epub_output_filename)