Skip to content

Commit 330b1ad

Browse files
committed
Add description config option
1 parent f24eb59 commit 330b1ad

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/book/bookconfig.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
88
pub struct BookConfig {
99
pub title: String,
1010
pub author: String,
11+
pub description: String,
1112
root: PathBuf,
1213
dest: PathBuf,
1314
src: PathBuf,
@@ -21,6 +22,7 @@ impl BookConfig {
2122
BookConfig {
2223
title: String::new(),
2324
author: String::new(),
25+
description: String::new(),
2426
root: root.to_owned(),
2527
dest: PathBuf::from("book"),
2628
src: PathBuf::from("src"),
@@ -54,9 +56,10 @@ impl BookConfig {
5456
// Extract data
5557

5658
debug!("[*]: Extracting data from config");
57-
// Title & author
59+
// Title, author, description
5860
if let Some(a) = config.find_path(&["title"]) { self.title = a.to_string().replace("\"", "") }
5961
if let Some(a) = config.find_path(&["author"]) { self.author = a.to_string().replace("\"", "") }
62+
if let Some(a) = config.find_path(&["description"]) { self.description = a.to_string().replace("\"", "") }
6063

6164
// Destination
6265
if let Some(a) = config.find_path(&["dest"]) {

src/book/mdbook.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,15 @@ impl MDBook {
351351
&self.config.author
352352
}
353353

354+
pub fn set_description(mut self, description: &str) -> Self {
355+
self.config.description = description.to_owned();
356+
self
357+
}
358+
359+
pub fn get_description(&self) -> &str {
360+
&self.config.description
361+
}
362+
354363
// Construct book
355364
fn parse_summary(&mut self) -> Result<(), Box<Error>> {
356365
// When append becomes stable, use self.content.append() ...

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ fn make_data(book: &MDBook) -> Result<BTreeMap<String,Json>, Box<Error>> {
241241
let mut data = BTreeMap::new();
242242
data.insert("language".to_owned(), "en".to_json());
243243
data.insert("title".to_owned(), book.get_title().to_json());
244+
data.insert("description".to_owned(), book.get_description().to_json());
244245
data.insert("favicon".to_owned(), "favicon.png".to_json());
245246

246247
let mut chapters = vec![];

src/theme/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="UTF-8">
55
<title>{{ title }}</title>
66
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
7-
<meta name="description" content="{% block description %}{% endblock %}">
7+
<meta name="description" content="{{ description }}">
88
<meta name="viewport" content="width=device-width, initial-scale=1">
99

1010
<base href="{{ path_to_root }}">

0 commit comments

Comments
 (0)