Browse Source

Add --root global argument. Fixes #899. (#932)

index-subcmd
ethereal Vincent Prouillet 4 years ago
parent
commit
94445ae745
7 changed files with 38 additions and 9 deletions
  1. +1
    -1
      components/site/src/lib.rs
  2. +6
    -1
      docs/content/documentation/getting-started/cli-usage.md
  3. +8
    -0
      src/cli.rs
  4. +3
    -2
      src/cmd/build.rs
  5. +3
    -3
      src/cmd/check.rs
  6. +8
    -2
      src/cmd/serve.rs
  7. +9
    -0
      src/main.rs

+ 1
- 1
components/site/src/lib.rs View File

@@ -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);


+ 6
- 1
docs/content/documentation/getting-started/cli-usage.md View 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


+ 8
- 0
src/cli.rs View File

@@ -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")


+ 3
- 2
src/cmd/build.rs View File

@@ -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());


+ 3
- 3
src/cmd/check.rs View File

@@ -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();


+ 8
- 2
src/cmd/serve.rs View File

@@ -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,


+ 9
- 0
src/main.rs View File

@@ -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"),


Loading…
Cancel
Save