Add description config option
This commit is contained in:
parent
f24eb59753
commit
330b1ad55d
|
@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
|
||||||
pub struct BookConfig {
|
pub struct BookConfig {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
|
pub description: String,
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
dest: PathBuf,
|
dest: PathBuf,
|
||||||
src: PathBuf,
|
src: PathBuf,
|
||||||
|
@ -21,6 +22,7 @@ impl BookConfig {
|
||||||
BookConfig {
|
BookConfig {
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
author: String::new(),
|
author: String::new(),
|
||||||
|
description: String::new(),
|
||||||
root: root.to_owned(),
|
root: root.to_owned(),
|
||||||
dest: PathBuf::from("book"),
|
dest: PathBuf::from("book"),
|
||||||
src: PathBuf::from("src"),
|
src: PathBuf::from("src"),
|
||||||
|
@ -54,9 +56,10 @@ impl BookConfig {
|
||||||
// Extract data
|
// Extract data
|
||||||
|
|
||||||
debug!("[*]: Extracting data from config");
|
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(&["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(&["author"]) { self.author = a.to_string().replace("\"", "") }
|
||||||
|
if let Some(a) = config.find_path(&["description"]) { self.description = a.to_string().replace("\"", "") }
|
||||||
|
|
||||||
// Destination
|
// Destination
|
||||||
if let Some(a) = config.find_path(&["dest"]) {
|
if let Some(a) = config.find_path(&["dest"]) {
|
||||||
|
|
|
@ -351,6 +351,15 @@ impl MDBook {
|
||||||
&self.config.author
|
&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
|
// Construct book
|
||||||
fn parse_summary(&mut self) -> Result<(), Box<Error>> {
|
fn parse_summary(&mut self) -> Result<(), Box<Error>> {
|
||||||
// When append becomes stable, use self.content.append() ...
|
// When append becomes stable, use self.content.append() ...
|
||||||
|
|
|
@ -241,6 +241,7 @@ fn make_data(book: &MDBook) -> Result<BTreeMap<String,Json>, Box<Error>> {
|
||||||
let mut data = BTreeMap::new();
|
let mut data = BTreeMap::new();
|
||||||
data.insert("language".to_owned(), "en".to_json());
|
data.insert("language".to_owned(), "en".to_json());
|
||||||
data.insert("title".to_owned(), book.get_title().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());
|
data.insert("favicon".to_owned(), "favicon.png".to_json());
|
||||||
|
|
||||||
let mut chapters = vec![];
|
let mut chapters = vec![];
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{ title }}</title>
|
<title>{{ title }}</title>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<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">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
<base href="{{ path_to_root }}">
|
<base href="{{ path_to_root }}">
|
||||||
|
|
Loading…
Reference in New Issue