From 95fba3f3570939ab602b167df47b9e5839a04579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Sat, 15 Feb 2020 23:13:37 +0100 Subject: [PATCH] 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. --- src/renderer/html_handlebars/hbs_renderer.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 0be92562..04284c50 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -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));