diff options
author | Thomas Letan <contact@thomasletan.fr> | 2019-08-04 21:12:35 +0200 |
---|---|---|
committer | Thomas Letan <contact@thomasletan.fr> | 2019-08-04 21:12:35 +0200 |
commit | 8e159bb379733710e7f0cf8b670bc8c63576e7be (patch) | |
tree | 983994d66b207392b9dae6fe8e5934ee811a15bb | |
parent | feature: Allows for specifying a cover image for your book (diff) |
fix: Address several errors returned by EPUB Validator
The reference is used is http://validator.idpf.org/
-rw-r--r-- | src/epub.rs | 12 | ||||
-rw-r--r-- | templates/chapter.xhtml | 11 | ||||
-rw-r--r-- | templates/content.opf | 6 | ||||
-rw-r--r-- | templates/main.css | 1 | ||||
-rw-r--r-- | templates/toc.ncx | 2 |
5 files changed, 22 insertions, 10 deletions
diff --git a/src/epub.rs b/src/epub.rs index 765f213..ebd68b4 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -42,7 +42,7 @@ fn create_container(tera : &Tera) -> Result<(), Error> { Ok(()) } -fn create_chapters(tera : &Tera, chapters : &Vec<Chapter<String>>) -> Result<Vec<String>, Error> { +fn create_chapters(tera : &Tera, chapters : &Vec<Chapter<String>>) -> Result<(), Error> { chapters.iter().enumerate() .map(|(idx, c)| { @@ -61,7 +61,9 @@ fn create_chapters(tera : &Tera, chapters : &Vec<Chapter<String>>) -> Result<Vec Ok(path) }) - .collect::<Result<Vec<String>, Error>>() + .collect::<Result<Vec<String>, Error>>()?; + + Ok(()) } fn template_dir(assets : &PathBuf) -> Result<String, Error> { @@ -122,7 +124,7 @@ pub fn generate(project : &Project<String>, assets : &PathBuf) -> Result<(), Err create_mimetype()?; create_container(&tera)?; - let files = create_chapters(&tera, &project.chapters)?; + create_chapters(&tera, &project.chapters)?; write_template_to( &tera, @@ -143,6 +145,10 @@ pub fn generate(project : &Project<String>, assets : &PathBuf) -> Result<(), Err install_fonts(assets, &fonts)?; + let files = project.chapters.iter().enumerate() + .map(|(idx, _)| idx) + .collect::<Vec<usize>>(); + let mut ctx = Context::new(); ctx.insert("title", &project.title); ctx.insert("author", &project.author); diff --git a/templates/chapter.xhtml b/templates/chapter.xhtml index a0508ed..b9a77d0 100644 --- a/templates/chapter.xhtml +++ b/templates/chapter.xhtml @@ -1,14 +1,19 @@ -<html lang="fr"> +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="fr" xml:lang="fr"> <head> <link rel="stylesheet" type="text/css" href="../Style/main.css" /> + <title> + {{ number }} – {{ chapter.title }} + </title> </head> <body> {% if chapter.title %} <h1> – {{ number }} – - <div class="title"> + <span class="title"> {% filter upper %}{{ chapter.title }}{% endfilter %} - </div> + </span> </h1> {% endif %} <div class="ogmarkup"> diff --git a/templates/content.opf b/templates/content.opf index b5dad1c..d182a33 100644 --- a/templates/content.opf +++ b/templates/content.opf @@ -17,15 +17,15 @@ <item href="Fonts/{{ f }}" id="{{ f }}" media-type="application/x-font-ttf" /> {% endfor %} {% for f in files %} - <item href="Text/{{ f }}" id="{{ f }}" media-type="application/xhtml+xml" /> + <item href="Text/{{ f }}.xhtml" id="ch{{ f }}" media-type="application/xhtml+xml" /> {% endfor %} {% if cover_extension %} - <item href="cover.{{ cover_extension }}" id="coverimage" media-type="image/jpeg" properties="cover-image" /> + <item href="cover.{{ cover_extension }}" id="coverimage" media-type="image/jpeg" /> {% endif %} </manifest> <spine toc="ncx"> {% for f in files %} - <itemref idref="{{ f }}" /> + <itemref idref="ch{{ f }}" /> {% endfor %} </spine> </package> diff --git a/templates/main.css b/templates/main.css index 56c52d5..22903aa 100644 --- a/templates/main.css +++ b/templates/main.css @@ -34,6 +34,7 @@ h1 { h1 .title { font-size: 120%; + display: block; } p { diff --git a/templates/toc.ncx b/templates/toc.ncx index 26a88f3..1f86972 100644 --- a/templates/toc.ncx +++ b/templates/toc.ncx @@ -10,7 +10,7 @@ </docTitle> <navMap> {% for info in chapters %} - <navPoint class="h1" id="ch1"> + <navPoint class="h1" id="ch{{ info.index + 1 }}"> <navLabel> <text>{{ info.index + 1 }}. {{ info.title }}</text> </navLabel> |