@@ -47,7 +47,7 @@ pub struct Site { | |||
impl Site { | |||
/// Parse a site at the given path. Defaults to the current dir | |||
/// Passing in a path is only used in tests | |||
/// Passing in a path is used in tests and when --root argument is passed | |||
pub fn new<P: AsRef<Path>>(path: P, config_file: &str) -> Result<Site> { | |||
let path = path.as_ref(); | |||
let mut config = get_config(path, config_file); | |||
@@ -50,12 +50,17 @@ You can override the default output directory `public` by passing another value | |||
$ zola build --output-dir $DOCUMENT_ROOT | |||
``` | |||
You can also point to a config file other than `config.toml` like so (note that the position of the `config` option is important): | |||
You can point to a config file other than `config.toml` like so (note that the position of the `config` option is important): | |||
```bash | |||
$ zola --config config.staging.toml build | |||
``` | |||
You can also process a project from a different directory with the `root` flag. If building a project 'out-of-tree' with the `root` flag, you may want to combine it with the `output-dir` flag. (Note that like `config`, the position is important): | |||
```bash | |||
$ zola --root /path/to/project build | |||
``` | |||
By default, drafts are not loaded. If you wish to include them, pass the `--drafts` flag. | |||
## serve | |||
@@ -6,6 +6,14 @@ pub fn build_cli() -> App<'static, 'static> { | |||
.author(crate_authors!()) | |||
.about(crate_description!()) | |||
.setting(AppSettings::SubcommandRequiredElseHelp) | |||
.arg( | |||
Arg::with_name("root") | |||
.short("r") | |||
.long("root") | |||
.takes_value(true) | |||
.default_value(".") | |||
.help("Directory to use as root of project") | |||
) | |||
.arg( | |||
Arg::with_name("config") | |||
.short("c") | |||
@@ -1,4 +1,4 @@ | |||
use std::env; | |||
use std::path::Path; | |||
use errors::Result; | |||
use site::Site; | |||
@@ -6,12 +6,13 @@ use site::Site; | |||
use crate::console; | |||
pub fn build( | |||
root_dir: &Path, | |||
config_file: &str, | |||
base_url: Option<&str>, | |||
output_dir: &str, | |||
include_drafts: bool, | |||
) -> Result<()> { | |||
let mut site = Site::new(env::current_dir().unwrap(), config_file)?; | |||
let mut site = Site::new(root_dir, config_file)?; | |||
site.set_output_path(output_dir); | |||
if let Some(b) = base_url { | |||
site.set_base_url(b.to_string()); | |||
@@ -1,5 +1,4 @@ | |||
use std::env; | |||
use std::path::PathBuf; | |||
use std::path::{Path,PathBuf}; | |||
use errors::Result; | |||
use site::Site; | |||
@@ -7,12 +6,13 @@ use site::Site; | |||
use crate::console; | |||
pub fn check( | |||
root_dir: &Path, | |||
config_file: &str, | |||
base_path: Option<&str>, | |||
base_url: Option<&str>, | |||
include_drafts: bool, | |||
) -> Result<()> { | |||
let bp = base_path.map(PathBuf::from).unwrap_or_else(|| env::current_dir().unwrap()); | |||
let bp = base_path.map(PathBuf::from).unwrap_or_else(|| PathBuf::from(root_dir)); | |||
let mut site = Site::new(bp, config_file)?; | |||
// Force the checking of external links | |||
site.config.enable_check_mode(); | |||
@@ -158,6 +158,7 @@ fn rebuild_done_handling(broadcaster: &Option<Sender>, res: Result<()>, reload_p | |||
} | |||
fn create_new_site( | |||
root_dir: &Path, | |||
interface: &str, | |||
port: u16, | |||
output_dir: &str, | |||
@@ -165,7 +166,7 @@ fn create_new_site( | |||
config_file: &str, | |||
include_drafts: bool, | |||
) -> Result<(Site, String)> { | |||
let mut site = Site::new(env::current_dir().unwrap(), config_file)?; | |||
let mut site = Site::new(root_dir, config_file)?; | |||
let base_address = format!("{}:{}", base_url, port); | |||
let address = format!("{}:{}", interface, port); | |||
@@ -190,6 +191,7 @@ fn create_new_site( | |||
} | |||
pub fn serve( | |||
root_dir: &Path, | |||
interface: &str, | |||
port: u16, | |||
output_dir: &str, | |||
@@ -201,7 +203,7 @@ pub fn serve( | |||
) -> Result<()> { | |||
let start = Instant::now(); | |||
let (mut site, address) = | |||
create_new_site(interface, port, output_dir, base_url, config_file, include_drafts)?; | |||
create_new_site(root_dir, interface, port, output_dir, base_url, config_file, include_drafts)?; | |||
console::report_elapsed_time(start); | |||
// Setup watchers | |||
@@ -443,6 +445,7 @@ pub fn serve( | |||
"-> Themes changed. The whole site will be reloaded.", | |||
); | |||
site = create_new_site( | |||
root_dir, | |||
interface, | |||
port, | |||
output_dir, | |||
@@ -457,6 +460,7 @@ pub fn serve( | |||
ChangeKind::Config => { | |||
console::info("-> Config changed. The whole site will be reloaded. The browser needs to be refreshed to make the changes visible."); | |||
site = create_new_site( | |||
root_dir, | |||
interface, | |||
port, | |||
output_dir, | |||
@@ -504,6 +508,7 @@ pub fn serve( | |||
"-> Themes changed. The whole site will be reloaded.", | |||
); | |||
site = create_new_site( | |||
root_dir, | |||
interface, | |||
port, | |||
output_dir, | |||
@@ -518,6 +523,7 @@ pub fn serve( | |||
(ChangeKind::Config, _) => { | |||
console::info("-> Config changed. The whole site will be reloaded. The browser needs to be refreshed to make the changes visible."); | |||
site = create_new_site( | |||
root_dir, | |||
interface, | |||
port, | |||
output_dir, | |||
@@ -1,3 +1,5 @@ | |||
use std::env; | |||
use std::path::PathBuf; | |||
use std::time::Instant; | |||
use utils::net::{get_available_port, port_is_available}; | |||
@@ -10,6 +12,10 @@ mod prompt; | |||
fn main() { | |||
let matches = cli::build_cli().get_matches(); | |||
let root_dir = match matches.value_of("root").unwrap() { | |||
"." => env::current_dir().unwrap(), | |||
path => PathBuf::from(path), | |||
}; | |||
let config_file = matches.value_of("config").unwrap(); | |||
match matches.subcommand() { | |||
@@ -27,6 +33,7 @@ fn main() { | |||
let start = Instant::now(); | |||
let output_dir = matches.value_of("output_dir").unwrap(); | |||
match cmd::build( | |||
&root_dir, | |||
config_file, | |||
matches.value_of("base_url"), | |||
output_dir, | |||
@@ -70,6 +77,7 @@ fn main() { | |||
let base_url = matches.value_of("base_url").unwrap(); | |||
console::info("Building site..."); | |||
match cmd::serve( | |||
&root_dir, | |||
interface, | |||
port, | |||
output_dir, | |||
@@ -90,6 +98,7 @@ fn main() { | |||
console::info("Checking site..."); | |||
let start = Instant::now(); | |||
match cmd::check( | |||
&root_dir, | |||
config_file, | |||
matches.value_of("base_path"), | |||
matches.value_of("base_url"), | |||