Skip to content

Commit 80deac9

Browse files
committed
Merge branch 'master' of https://github.com/azerupi/mdBook
2 parents 625f508 + 3e8151e commit 80deac9

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

book-example/book.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"title": "mdBook Documentation",
3+
"description": "Create book from markdown files. Like Gitbook but implemented in Rust",
34
"author": "Mathieu David"
45
}

book-example/src/format/config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Here is an example of what a ***book.json*** file might look like:
88
{
99
"title": "Example book",
1010
"author": "Name",
11+
"description": "The example book covers examples.",
1112
"dest": "output/my-book"
1213
}
1314
```
@@ -16,6 +17,7 @@ Here is an example of what a ***book.json*** file might look like:
1617

1718
- **title:** title of the book
1819
- **author:** author of the book
20+
- **description:** description, which is added as meta in the html head of each page.
1921
- **dest:** path to the directory where you want your book to be rendered. If a relative path is given it will be relative to the parent directory of the source directory
2022

2123
***note:*** *the supported configurable parameters are scarce at the moment, but more will be added in the future*

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)