aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Letan <contact@thomasletan.fr>2019-08-04 10:56:56 +0200
committerThomas Letan <contact@thomasletan.fr>2019-08-04 10:56:56 +0200
commited5ca28027959598a5c2f78987e086490f5259b0 (patch)
treeae274c58e83e1b1ded80ebe9f8398b9d6a92e44e
parentrefactor: Use a template engine for generating the EPUB documents (diff)
feature: Support optional title in rendering
-rw-r--r--src/epub.rs2
-rw-r--r--src/project.rs8
-rw-r--r--templates/chapter.xhtml7
3 files changed, 11 insertions, 6 deletions
diff --git a/src/epub.rs b/src/epub.rs
index c9cd541..2798083 100644
--- a/src/epub.rs
+++ b/src/epub.rs
@@ -46,7 +46,7 @@ fn create_chapters(tera : &Tera, chapters : &Vec<Chapter<String>>) -> Result<Vec
chapters.iter().enumerate()
.map(|(idx, c)| {
let mut ctx = Context::new();
- ctx.insert("content", &c.content);
+ ctx.insert("chapter", &c);
let path : String = format!("{}.xhtml", idx);
diff --git a/src/project.rs b/src/project.rs
index 0bf35a9..a0a9aed 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -2,7 +2,7 @@ use std::fs;
use std::path::PathBuf;
use std::env::current_dir;
-use serde_derive::Deserialize;
+use serde_derive::{Deserialize, Serialize};
use ogmarkup::typography::Typography;
@@ -13,9 +13,9 @@ const PROJECT_FILE: &'static str = "Book.toml";
#[derive(Debug)]
pub struct Error(pub String);
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub struct Chapter<A> {
- pub title: String,
+ pub title: Option<String>,
pub content: A,
}
@@ -52,7 +52,7 @@ impl Chapter<Vec<PathBuf>> {
}
}
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Serialize, Deserialize)]
pub struct Project<A> {
pub author: String,
pub title: String,
diff --git a/templates/chapter.xhtml b/templates/chapter.xhtml
index 84541d0..d18b69d 100644
--- a/templates/chapter.xhtml
+++ b/templates/chapter.xhtml
@@ -2,6 +2,11 @@
<head>
</head>
<body>
- {{ content }}
+ {% if chapter.title %}
+ <h1>
+ {{ chapter.title }}
+ </h1>
+ {% endif %}
+ {{ chapter.content }}
</body>
</html>