Revert "Allow default base-path command line option to be set for building and serving"

This reverts commit 1815155c1d.
This commit is contained in:
Vincent Prouillet 2019-04-20 12:50:34 +02:00
parent 2aa3ea758b
commit debe0633bc
6 changed files with 20 additions and 65 deletions

View file

@ -66,7 +66,7 @@ pub struct Site {
impl Site {
/// Parse a site at the given path. Defaults to the current dir
/// Passing in a path is possible using the `base-path` command line build option
/// Passing in a path is only used in tests
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);

View file

@ -36,14 +36,6 @@ $ zola build --base-url $DEPLOY_URL
This is useful for example when you want to deploy previews of a site to a dynamic URL, such as Netlify
deploy previews.
You can override the default `base_path` by passing a new directory to the `base-path` flag. If no `base-path` flag
is provided, zola defaults to your current working directory. This is useful if your zola project is located in
a different directory from where you're executing zola from.
```bash
$ zola build --base-path /path/to/zola/site
```
You can override the default output directory 'public' by passing a other value to the `output-dir` flag.
```bash
@ -75,7 +67,6 @@ $ zola serve --interface 0.0.0.0
$ zola serve --interface 0.0.0.0 --port 2000
$ zola serve --interface 0.0.0.0 --base-url 127.0.0.1
$ zola serve --interface 0.0.0.0 --port 2000 --output-dir www/public
$ zola serve --interface 0.0.0.0 --port 2000 --base-path mysite/ --output-dir mysite/www/public
$ zola serve --watch-only
```

View file

@ -30,11 +30,6 @@ pub fn build_cli() -> App<'static, 'static> {
.long("base-url")
.takes_value(true)
.help("Force the base URL to be that value (default to the one in config.toml)"),
Arg::with_name("base_path")
.short("b")
.long("base-path")
.takes_value(true)
.help("Force the base site path to a certain directory [default: the current working directory]"),
Arg::with_name("output_dir")
.short("o")
.long("output-dir")
@ -61,11 +56,6 @@ pub fn build_cli() -> App<'static, 'static> {
.default_value("public")
.takes_value(true)
.help("Outputs the generated site in the given path"),
Arg::with_name("base_path")
.short("b")
.long("base-path")
.takes_value(true)
.help("Force the base site path to a certain directory [default: the current working directory]"),
Arg::with_name("base_url")
.short("u")
.long("base-url")

View file

@ -1,19 +1,12 @@
use std::env;
use std::path::PathBuf;
use errors::Result;
use site::Site;
use console;
pub fn build(
config_file: &str,
base_path: Option<&str>,
base_url: Option<&str>,
output_dir: &str,
) -> Result<()> {
let bp = base_path.map(PathBuf::from).unwrap_or(env::current_dir().unwrap());
let mut site = Site::new(bp, config_file)?;
pub fn build(config_file: &str, base_url: Option<&str>, output_dir: &str) -> Result<()> {
let mut site = Site::new(env::current_dir().unwrap(), config_file)?;
site.set_output_path(output_dir);
if let Some(b) = base_url {
site.set_base_url(b.to_string());

View file

@ -114,15 +114,14 @@ fn rebuild_done_handling(broadcaster: &Option<Sender>, res: Result<()>, reload_p
}
}
fn create_new_site<P: AsRef<Path>>(
fn create_new_site(
interface: &str,
port: u16,
output_dir: &str,
base_path: P,
base_url: &str,
config_file: &str,
) -> Result<(Site, String)> {
let mut site = Site::new(base_path, config_file)?;
let mut site = Site::new(env::current_dir().unwrap(), config_file)?;
let base_address = format!("{}:{}", base_url, port);
let address = format!("{}:{}", interface, port);
@ -167,15 +166,12 @@ pub fn serve(
interface: &str,
port: u16,
output_dir: &str,
base_path: Option<&str>,
base_url: &str,
config_file: &str,
watch_only: bool,
) -> Result<()> {
let start = Instant::now();
let bp = base_path.map(PathBuf::from).unwrap_or(env::current_dir().unwrap());
let (mut site, address) =
create_new_site(interface, port, output_dir, bp.clone(), base_url, config_file)?;
let (mut site, address) = create_new_site(interface, port, output_dir, base_url, config_file)?;
console::report_elapsed_time(start);
// Setup watchers
@ -184,28 +180,28 @@ pub fn serve(
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(1)).unwrap();
watcher
.watch(bp.join("content/"), RecursiveMode::Recursive)
.watch("content/", RecursiveMode::Recursive)
.map_err(|e| ZolaError::chain("Can't watch the `content` folder. Does it exist?", e))?;
watcher
.watch(bp.join(config_file), RecursiveMode::Recursive)
.watch(config_file, RecursiveMode::Recursive)
.map_err(|e| ZolaError::chain("Can't watch the `config` file. Does it exist?", e))?;
if bp.join("static").exists() {
if Path::new("static").exists() {
watching_static = true;
watcher
.watch(bp.join("static/"), RecursiveMode::Recursive)
.watch("static/", RecursiveMode::Recursive)
.map_err(|e| ZolaError::chain("Can't watch the `static` folder.", e))?;
}
if bp.join("templates").exists() {
if Path::new("templates").exists() {
watching_templates = true;
watcher
.watch(bp.join("templates/"), RecursiveMode::Recursive)
.watch("templates/", RecursiveMode::Recursive)
.map_err(|e| ZolaError::chain("Can't watch the `templates` folder.", e))?;
}
// Sass support is optional so don't make it an error to no have a sass folder
let _ = watcher.watch(bp.join("sass/"), RecursiveMode::Recursive);
let _ = watcher.watch("sass/", RecursiveMode::Recursive);
let ws_address = format!("{}:{}", interface, site.live_reload.unwrap());
let output_path = Path::new(output_dir).to_path_buf();
@ -262,6 +258,8 @@ pub fn serve(
None
};
let pwd = env::current_dir().unwrap();
let mut watchers = vec!["content", "config.toml"];
if watching_static {
watchers.push("static");
@ -275,7 +273,7 @@ pub fn serve(
println!(
"Listening for changes in {}{}{{{}}}",
bp.display(),
pwd.display(),
MAIN_SEPARATOR,
watchers.join(", ")
);
@ -351,8 +349,7 @@ pub fn serve(
if path.is_file() && is_temp_file(&path) {
continue;
}
let (change_kind, partial_path) =
detect_change_kind(&bp.canonicalize().unwrap(), &path);
let (change_kind, partial_path) = detect_change_kind(&pwd, &path);
// We only care about changes in non-empty folders
if path.is_dir() && is_folder_empty(&path) {
@ -384,7 +381,6 @@ pub fn serve(
interface,
port,
output_dir,
bp.clone(),
base_url,
config_file,
)
@ -405,7 +401,7 @@ pub fn serve(
);
let start = Instant::now();
match detect_change_kind(&bp.canonicalize().unwrap(), &path) {
match detect_change_kind(&pwd, &path) {
(ChangeKind::Content, _) => {
console::info(&format!("-> Content changed {}", path.display()));
// Force refresh
@ -424,7 +420,6 @@ pub fn serve(
interface,
port,
output_dir,
bp.clone(),
base_url,
config_file,
)

View file

@ -46,12 +46,7 @@ fn main() {
console::info("Building site...");
let start = Instant::now();
let output_dir = matches.value_of("output_dir").unwrap();
match cmd::build(
config_file,
matches.value_of("base_path"),
matches.value_of("base_url"),
output_dir,
) {
match cmd::build(config_file, matches.value_of("base_url"), output_dir) {
Ok(()) => console::report_elapsed_time(start),
Err(e) => {
console::unravel_errors("Failed to build the site", &e);
@ -84,18 +79,9 @@ fn main() {
}
let watch_only = matches.is_present("watch_only");
let output_dir = matches.value_of("output_dir").unwrap();
let base_path = matches.value_of("base_path");
let base_url = matches.value_of("base_url").unwrap();
console::info("Building site...");
match cmd::serve(
interface,
port,
output_dir,
base_path,
base_url,
config_file,
watch_only,
) {
match cmd::serve(interface, port, output_dir, base_url, config_file, watch_only) {
Ok(()) => (),
Err(e) => {
console::unravel_errors("", &e);