Initial implementation for reading the config file: book.json #7
This commit is contained in:
parent
ef00851b8e
commit
9b4298c066
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<title>mdBook Documentation</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{% block description %}{% endblock %}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div class="page">
|
||||
<div id="menu-bar" class="menu-bar">
|
||||
<i id="sidebar-toggle" class="fa fa-bars left"></i>
|
||||
<h1 class="menu-title"></h1>
|
||||
<h1 class="menu-title">mdBook Documentation</h1>
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
|
|
|
@ -109,11 +109,13 @@ html, body {
|
|||
}
|
||||
|
||||
.menu-bar {
|
||||
position: relative;
|
||||
height: 50px;
|
||||
color: #CCC;
|
||||
}
|
||||
|
||||
.menu-bar i {
|
||||
line-height: 50px;
|
||||
-webkit-transition: color 0.5s; /* Safari */
|
||||
-o-transition: color 0.5s; /* Opera */
|
||||
-moz-transition: color 0.5s; /* Mozilla Firefox */
|
||||
|
@ -125,6 +127,32 @@ html, body {
|
|||
color: #333;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
color: #7E7E7E;
|
||||
display: inline-block;
|
||||
font-weight: 200;
|
||||
font-size: 20px;
|
||||
line-height: 50px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.5s ease-in-out; /* Safari */
|
||||
-o-transition: opacity 0.5s ease-in-out; /* Opera */
|
||||
-moz-transition: opacity 0.5s ease-in-out; /* Mozilla Firefox */
|
||||
transition: opacity 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
.menu-title:hover {
|
||||
color: #7E7E7E;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<title>mdBook Documentation</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{% block description %}{% endblock %}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div class="page">
|
||||
<div id="menu-bar" class="menu-bar">
|
||||
<i id="sidebar-toggle" class="fa fa-bars left"></i>
|
||||
<h1 class="menu-title"></h1>
|
||||
<h1 class="menu-title">mdBook Documentation</h1>
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<title>mdBook Documentation</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{% block description %}{% endblock %}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div class="page">
|
||||
<div id="menu-bar" class="menu-bar">
|
||||
<i id="sidebar-toggle" class="fa fa-bars left"></i>
|
||||
<h1 class="menu-title"></h1>
|
||||
<h1 class="menu-title">mdBook Documentation</h1>
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<title>mdBook Documentation</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{% block description %}{% endblock %}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div class="page">
|
||||
<div id="menu-bar" class="menu-bar">
|
||||
<i id="sidebar-toggle" class="fa fa-bars left"></i>
|
||||
<h1 class="menu-title"></h1>
|
||||
<h1 class="menu-title">mdBook Documentation</h1>
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
<title>mdBook Documentation</title>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta name="description" content="{% block description %}{% endblock %}">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div class="page">
|
||||
<div id="menu-bar" class="menu-bar">
|
||||
<i id="sidebar-toggle" class="fa fa-bars left"></i>
|
||||
<h1 class="menu-title"></h1>
|
||||
<h1 class="menu-title">mdBook Documentation</h1>
|
||||
</div>
|
||||
|
||||
<div id="content" class="content">
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"title": "mdBook Documentation"
|
||||
}
|
|
@ -1,3 +1,7 @@
|
|||
extern crate rustc_serialize;
|
||||
use self::rustc_serialize::json::Json;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -23,6 +27,26 @@ impl BookConfig {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_config(&mut self) -> &mut Self {
|
||||
|
||||
// If the file does not exist, return early
|
||||
let mut config_file = match File::open(self.src.join("book.json")) {
|
||||
Ok(f) => f,
|
||||
Err(_) => return self,
|
||||
};
|
||||
|
||||
let mut data = String::new();
|
||||
config_file.read_to_string(&mut data).unwrap();
|
||||
|
||||
// Convert to JSON
|
||||
let config = Json::from_str(&data).unwrap();
|
||||
|
||||
// Extract data
|
||||
if let Some(a) = config.find_path(&["title"]) { self.title = a.to_string().replace("\"", "") }
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn dest(&self) -> &Path {
|
||||
&self.dest
|
||||
}
|
||||
|
@ -40,4 +64,5 @@ impl BookConfig {
|
|||
self.src = src.to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -111,6 +111,11 @@ impl MDBook {
|
|||
|
||||
|
||||
// Builder functions
|
||||
pub fn read_config(mut self) -> Self {
|
||||
self.config.read_config();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_dest(mut self, dest: &Path) -> Self {
|
||||
self.config.set_dest(dest);
|
||||
self
|
||||
|
|
|
@ -56,7 +56,7 @@ fn init(args: &ArgMatches) -> Result<(), Box<Error>> {
|
|||
|
||||
fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
|
||||
let book_dir = get_book_dir(args);
|
||||
let mut book = MDBook::new(&book_dir);
|
||||
let mut book = MDBook::new(&book_dir).read_config();
|
||||
|
||||
book.build()
|
||||
}
|
||||
|
|
|
@ -109,11 +109,13 @@ html, body {
|
|||
}
|
||||
|
||||
.menu-bar {
|
||||
position: relative;
|
||||
height: 50px;
|
||||
color: #CCC;
|
||||
}
|
||||
|
||||
.menu-bar i {
|
||||
line-height: 50px;
|
||||
-webkit-transition: color 0.5s; /* Safari */
|
||||
-o-transition: color 0.5s; /* Opera */
|
||||
-moz-transition: color 0.5s; /* Mozilla Firefox */
|
||||
|
@ -125,6 +127,32 @@ html, body {
|
|||
color: #333;
|
||||
}
|
||||
|
||||
.menu-title {
|
||||
color: #7E7E7E;
|
||||
display: inline-block;
|
||||
font-weight: 200;
|
||||
font-size: 20px;
|
||||
line-height: 50px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
text-align: center;
|
||||
margin: 0;
|
||||
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.5s ease-in-out; /* Safari */
|
||||
-o-transition: opacity 0.5s ease-in-out; /* Opera */
|
||||
-moz-transition: opacity 0.5s ease-in-out; /* Mozilla Firefox */
|
||||
transition: opacity 0.5s ease-in-out;
|
||||
}
|
||||
|
||||
.menu-title:hover {
|
||||
color: #7E7E7E;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
|
|
Loading…
Reference in New Issue