|
@@ -4,22 +4,37 @@ extern crate fs_extra;
|
4
|
4
|
#[macro_use]
|
5
|
5
|
extern crate lazy_static;
|
6
|
6
|
extern crate regex;
|
|
7
|
+extern crate toml;
|
7
|
8
|
extern crate uuid;
|
8
|
9
|
|
9
|
10
|
use std::{env, fs};
|
10
|
11
|
|
11
|
12
|
use clap::{App, Arg};
|
12
|
13
|
use fs_extra::dir;
|
|
14
|
+use toml::Value;
|
13
|
15
|
|
|
16
|
+use config::Config;
|
14
|
17
|
use post::{parse_post, read_posts_dir};
|
15
|
18
|
use write::{write_post, write_post_listing};
|
16
|
19
|
|
|
20
|
+mod config;
|
17
|
21
|
mod post;
|
18
|
22
|
mod render;
|
19
|
23
|
mod write;
|
20
|
24
|
|
21
|
25
|
fn build() {
|
22
|
26
|
let cwd = env::current_dir().expect("Couldn't read current directory");
|
|
27
|
+ let config = match fs::read_to_string(cwd.join("tlon.toml")) {
|
|
28
|
+ Ok(contents) => match contents.parse::<Value>() {
|
|
29
|
+ Ok(config) => Config {
|
|
30
|
+ site_name: String::from(config["site_name"].as_str().unwrap()),
|
|
31
|
+ },
|
|
32
|
+ Err(_) => panic!("Invalid tlon.toml"),
|
|
33
|
+ },
|
|
34
|
+ Err(_) => {
|
|
35
|
+ panic!("Can't find tlon.toml");
|
|
36
|
+ }
|
|
37
|
+ };
|
23
|
38
|
|
24
|
39
|
match fs::read_dir(cwd.join("public")) {
|
25
|
40
|
Ok(_) => {
|
|
@@ -72,6 +87,10 @@ fn new(name: &str) {
|
72
|
87
|
let project_path = cwd.join(name);
|
73
|
88
|
|
74
|
89
|
fs::create_dir(&project_path).expect(&format!("Couldn't create directory '{}'", &name));
|
|
90
|
+ fs::write(
|
|
91
|
+ project_path.join("tlon.toml"),
|
|
92
|
+ format!("site_name = \"{}\"", &name),
|
|
93
|
+ ).expect("Could not create tlon.toml");
|
75
|
94
|
|
76
|
95
|
for dir in &["posts", "public", "templates", "css", "js"] {
|
77
|
96
|
fs::create_dir(&project_path.join(&dir))
|
|
@@ -161,6 +180,10 @@ mod tests {
|
161
|
180
|
"",
|
162
|
181
|
fs::read_to_string(&project_dir.join("js").join("index.js")).unwrap()
|
163
|
182
|
);
|
|
183
|
+ assert_eq!(
|
|
184
|
+ format!("site_name = \"{}\"", &uuid),
|
|
185
|
+ fs::read_to_string(&project_dir.join("tlon.toml")).unwrap()
|
|
186
|
+ );
|
164
|
187
|
|
165
|
188
|
fs::remove_dir_all(project_dir).unwrap();
|
166
|
189
|
}
|
|
@@ -207,6 +230,7 @@ mod tests {
|
207
|
230
|
project_dir.join("posts").join("first-post.md"),
|
208
|
231
|
"# First post\n\nThis is the first post\n\nIt has multiple paragraphs",
|
209
|
232
|
).unwrap();
|
|
233
|
+ fs::write(project_dir.join("tlon.toml"), "site_name = \"Test Site\"").unwrap();
|
210
|
234
|
|
211
|
235
|
build();
|
212
|
236
|
|