2017-02-23 08:34:57 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate error_chain;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde;
|
2016-12-06 06:55:17 +00:00
|
|
|
extern crate toml;
|
2016-12-06 08:27:03 +00:00
|
|
|
extern crate walkdir;
|
|
|
|
extern crate pulldown_cmark;
|
|
|
|
extern crate regex;
|
2016-12-06 11:53:14 +00:00
|
|
|
extern crate tera;
|
2016-12-11 06:05:03 +00:00
|
|
|
extern crate glob;
|
2017-02-23 08:34:57 +00:00
|
|
|
extern crate syntect;
|
2017-03-03 08:12:40 +00:00
|
|
|
extern crate slug;
|
2017-03-06 11:58:31 +00:00
|
|
|
extern crate chrono;
|
2016-12-11 06:05:03 +00:00
|
|
|
|
2017-03-06 10:35:56 +00:00
|
|
|
extern crate staticfile;
|
|
|
|
extern crate iron;
|
|
|
|
extern crate mount;
|
|
|
|
extern crate notify;
|
|
|
|
extern crate ws;
|
|
|
|
|
2016-12-06 05:51:33 +00:00
|
|
|
|
2017-03-03 08:12:40 +00:00
|
|
|
use std::time::Instant;
|
|
|
|
|
2016-12-13 06:22:24 +00:00
|
|
|
mod utils;
|
2016-12-06 05:51:33 +00:00
|
|
|
mod config;
|
|
|
|
mod errors;
|
|
|
|
mod cmd;
|
2016-12-06 08:27:03 +00:00
|
|
|
mod page;
|
2016-12-11 06:05:03 +00:00
|
|
|
mod front_matter;
|
2017-03-03 08:12:40 +00:00
|
|
|
mod site;
|
2017-03-07 12:34:31 +00:00
|
|
|
mod markdown;
|
2016-12-06 06:55:17 +00:00
|
|
|
|
2016-12-06 05:51:33 +00:00
|
|
|
|
|
|
|
fn main() {
|
2017-02-23 08:34:57 +00:00
|
|
|
let matches = clap_app!(Gutenberg =>
|
2016-12-06 05:51:33 +00:00
|
|
|
(version: crate_version!())
|
|
|
|
(author: "Vincent Prouillet")
|
|
|
|
(about: "Static site generator")
|
|
|
|
(@setting SubcommandRequiredElseHelp)
|
2017-02-23 08:34:57 +00:00
|
|
|
(@subcommand init =>
|
2016-12-06 05:51:33 +00:00
|
|
|
(about: "Create a new Gutenberg project")
|
|
|
|
(@arg name: +required "Name of the project. Will create a directory with that name in the current directory")
|
|
|
|
)
|
2016-12-06 08:27:03 +00:00
|
|
|
(@subcommand build =>
|
|
|
|
(about: "Builds the site")
|
|
|
|
)
|
2017-03-03 08:12:40 +00:00
|
|
|
(@subcommand serve =>
|
|
|
|
(about: "Serve the site. Rebuild and reload on change automatically")
|
|
|
|
(@arg interface: "Interface to bind on (default to 127.0.0.1)")
|
|
|
|
(@arg port: "Which port to use (default to 1111)")
|
|
|
|
)
|
2016-12-06 05:51:33 +00:00
|
|
|
).get_matches();
|
|
|
|
|
|
|
|
match matches.subcommand() {
|
2016-12-19 07:58:03 +00:00
|
|
|
("init", Some(matches)) => {
|
2016-12-06 05:51:33 +00:00
|
|
|
match cmd::create_new_project(matches.value_of("name").unwrap()) {
|
2016-12-06 08:27:03 +00:00
|
|
|
Ok(()) => {
|
|
|
|
println!("Project created");
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
println!("Error: {}", e);
|
|
|
|
::std::process::exit(1);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2016-12-11 06:05:03 +00:00
|
|
|
("build", Some(_)) => {
|
2017-03-03 08:12:40 +00:00
|
|
|
let start = Instant::now();
|
|
|
|
match cmd::build() {
|
2016-12-06 08:27:03 +00:00
|
|
|
Ok(()) => {
|
2017-03-03 08:12:40 +00:00
|
|
|
let duration = start.elapsed();
|
|
|
|
println!("Site built in {}s.", duration.as_secs());
|
2016-12-06 08:27:03 +00:00
|
|
|
},
|
|
|
|
Err(e) => {
|
2016-12-13 06:22:24 +00:00
|
|
|
println!("Failed to build the site");
|
|
|
|
println!("Error: {}", e);
|
|
|
|
for e in e.iter().skip(1) {
|
|
|
|
println!("Reason: {}", e)
|
|
|
|
}
|
2016-12-06 08:27:03 +00:00
|
|
|
::std::process::exit(1);
|
|
|
|
},
|
2016-12-06 05:51:33 +00:00
|
|
|
};
|
|
|
|
},
|
2017-03-03 08:12:40 +00:00
|
|
|
("serve", Some(matches)) => {
|
|
|
|
let interface = matches.value_of("interface").unwrap_or("127.0.0.1");
|
|
|
|
let port = matches.value_of("port").unwrap_or("1111");
|
|
|
|
match cmd::serve(interface, port) {
|
2017-03-06 10:35:56 +00:00
|
|
|
Ok(()) => (),
|
2017-03-03 08:12:40 +00:00
|
|
|
Err(e) => {
|
|
|
|
println!("Error: {}", e);
|
|
|
|
::std::process::exit(1);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2016-12-06 05:51:33 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|