summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu David <mathieudavid@mathieudavid.org>2016-03-01 18:33:55 +0100
committerMathieu David <mathieudavid@mathieudavid.org>2016-03-01 18:33:55 +0100
commit80deac90d9932582fed522a2eb993cc6df173d11 (patch)
tree713bff0b20d82b69f5f65431eb16d6d7361280d0
parent625f5081fa0be6a7b575f95239ce963387a61836 (diff)
parent3e8151e8e38ca09fff587e76a165d1ccca528c09 (diff)
Merge branch 'master' of https://github.com/azerupi/mdBookv0.0.10
-rw-r--r--book-example/book.json1
-rw-r--r--book-example/src/format/config.md2
-rw-r--r--src/book/bookconfig.rs5
-rw-r--r--src/book/mdbook.rs9
-rw-r--r--src/renderer/html_handlebars/hbs_renderer.rs1
-rw-r--r--src/theme/index.hbs2
6 files changed, 18 insertions, 2 deletions
diff --git a/book-example/book.json b/book-example/book.json
index 7bd69391..aba0a400 100644
--- a/book-example/book.json
+++ b/book-example/book.json
@@ -1,4 +1,5 @@
{
"title": "mdBook Documentation",
+ "description": "Create book from markdown files. Like Gitbook but implemented in Rust",
"author": "Mathieu David"
}
diff --git a/book-example/src/format/config.md b/book-example/src/format/config.md
index ac8fb889..72794e87 100644
--- a/book-example/src/format/config.md
+++ b/book-example/src/format/config.md
@@ -8,6 +8,7 @@ Here is an example of what a ***book.json*** file might look like:
{
"title": "Example book",
"author": "Name",
+ "description": "The example book covers examples.",
"dest": "output/my-book"
}
```
@@ -16,6 +17,7 @@ Here is an example of what a ***book.json*** file might look like:
- **title:** title of the book
- **author:** author of the book
+- **description:** description, which is added as meta in the html head of each page.
- **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
***note:*** *the supported configurable parameters are scarce at the moment, but more will be added in the future*
diff --git a/src/book/bookconfig.rs b/src/book/bookconfig.rs
index 700469f7..95ac2caf 100644
--- a/src/book/bookconfig.rs
+++ b/src/book/bookconfig.rs
@@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
pub struct BookConfig {
pub title: String,
pub author: String,
+ pub description: String,
root: PathBuf,
dest: PathBuf,
src: PathBuf,
@@ -21,6 +22,7 @@ impl BookConfig {
BookConfig {
title: String::new(),
author: String::new(),
+ description: String::new(),
root: root.to_owned(),
dest: PathBuf::from("book"),
src: PathBuf::from("src"),
@@ -54,9 +56,10 @@ impl BookConfig {
// Extract data
debug!("[*]: Extracting data from config");
- // Title & author
+ // Title, author, description
if let Some(a) = config.find_path(&["title"]) { self.title = a.to_string().replace("\"", "") }
if let Some(a) = config.find_path(&["author"]) { self.author = a.to_string().replace("\"", "") }
+ if let Some(a) = config.find_path(&["description"]) { self.description = a.to_string().replace("\"", "") }
// Destination
if let Some(a) = config.find_path(&["dest"]) {
diff --git a/src/book/mdbook.rs b/src/book/mdbook.rs
index 521606d3..db27830f 100644
--- a/src/book/mdbook.rs
+++ b/src/book/mdbook.rs
@@ -351,6 +351,15 @@ impl MDBook {
&self.config.author
}
+ pub fn set_description(mut self, description: &str) -> Self {
+ self.config.description = description.to_owned();
+ self
+ }
+
+ pub fn get_description(&self) -> &str {
+ &self.config.description
+ }
+
// Construct book
fn parse_summary(&mut self) -> Result<(), Box<Error>> {
// When append becomes stable, use self.content.append() ...
diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs
index 613972fe..e9d9aa15 100644
--- a/src/renderer/html_handlebars/hbs_renderer.rs
+++ b/src/renderer/html_handlebars/hbs_renderer.rs
@@ -241,6 +241,7 @@ fn make_data(book: &MDBook) -> Result<BTreeMap<String,Json>, Box<Error>> {
let mut data = BTreeMap::new();
data.insert("language".to_owned(), "en".to_json());
data.insert("title".to_owned(), book.get_title().to_json());
+ data.insert("description".to_owned(), book.get_description().to_json());
data.insert("favicon".to_owned(), "favicon.png".to_json());
let mut chapters = vec![];
diff --git a/src/theme/index.hbs b/src/theme/index.hbs
index 98c959cf..2bd43c96 100644
--- a/src/theme/index.hbs
+++ b/src/theme/index.hbs
@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>{{ title }}</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
- <meta name="description" content="{% block description %}{% endblock %}">
+ <meta name="description" content="{{ description }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<base href="{{ path_to_root }}">