Add a case for an empty `book_title` parameter

Html page title for every chapter in the book is created by the following code:
```rust
let title: String;
{
	let book_title = ctx
	.data
	.get("book_title")
	.and_then(serde_json::Value::as_str)
	.unwrap_or("");

	title = ch.name.clone() + " - " + book_title;
}
```

If the `book.toml` file is missing, and `book_title` parameter is empty, there's an awkward ` - ` string hanging at the end of each chapter's title.

This PR adds a `match` case to handle that kind of situation.
This commit is contained in:
Tomasz Różański 2020-02-15 23:13:37 +01:00
parent d5999849d9
commit 95fba3f357
1 changed files with 5 additions and 1 deletions

View File

@ -61,7 +61,11 @@ impl HtmlHandlebars {
.get("book_title")
.and_then(serde_json::Value::as_str)
.unwrap_or("");
title = ch.name.clone() + " - " + book_title;
title = match book_title {
"" => ch.name.clone(),
_ => ch.name.clone() + " - " + book_title,
}
}
ctx.data.insert("path".to_owned(), json!(path));