Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/azerupi/mdBook
Browse files Browse the repository at this point in the history
  • Loading branch information
azerupi committed Mar 1, 2016
2 parents 625f508 + 3e8151e commit 80deac9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions book-example/book.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "mdBook Documentation",
"description": "Create book from markdown files. Like Gitbook but implemented in Rust",
"author": "Mathieu David"
}
2 changes: 2 additions & 0 deletions book-example/src/format/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```
Expand All @@ -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*
5 changes: 4 additions & 1 deletion src/book/bookconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
Expand Down Expand Up @@ -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"]) {
Expand Down
9 changes: 9 additions & 0 deletions src/book/mdbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() ...
Expand Down
1 change: 1 addition & 0 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down
2 changes: 1 addition & 1 deletion src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}">
Expand Down

0 comments on commit 80deac9

Please sign in to comment.