diff --git a/CHANGELOG.md b/CHANGELOG.md index caa320d..9f6c2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Defaults to compressed Sass output - Fix regression wrt co-located assets slug detecting - Rename `url` from page front-matter to `path` to be consistent +- Add a `base-url` flag to the `build` command to override the URL from config.toml ## 0.1.3 (2017-08-31) diff --git a/docs/content/documentation/getting-started/cli-usage.md b/docs/content/documentation/getting-started/cli-usage.md index ebcddd3..f852961 100644 --- a/docs/content/documentation/getting-started/cli-usage.md +++ b/docs/content/documentation/getting-started/cli-usage.md @@ -27,6 +27,12 @@ This will build the whole site in the `public` directory. $ gutenberg build ``` +You can override the config `base_url` by passing a new URL to the `base-url` flag. + +```bash +$ gutenberg build --base-url https://59a896e2cf321c2dcfd2d6de--tera.netlify.com/ +``` + ## serve This will build and serve the site using a local server. You can also specify diff --git a/src/cli.rs b/src/cli.rs index 75dd83d..122c8c8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -14,6 +14,7 @@ pub fn build_cli() -> App<'static, 'static> { ) (@subcommand build => (about: "Builds the site") + (@arg base_url: -u --base-url +takes_value "Force the base URL to be that value (default to the one in config.toml)") ) (@subcommand serve => (about: "Serve the site. Rebuild and reload on change automatically") diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 5ee0491..c2654f5 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -5,8 +5,11 @@ use site::Site; use console; -pub fn build(config_file: &str) -> Result<()> { +pub fn build(config_file: &str, base_url: Option<&str>) -> Result<()> { let mut site = Site::new(env::current_dir().unwrap(), config_file)?; + if let Some(b) = base_url { + site.config.base_url = b.to_string(); + } site.load()?; console::notify_site_size(&site); console::warn_about_ignored_pages(&site); diff --git a/src/main.rs b/src/main.rs index 2ae977d..adefc3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,10 +40,10 @@ fn main() { }, }; }, - ("build", Some(_)) => { + ("build", Some(matches)) => { console::info("Building site..."); let start = Instant::now(); - match cmd::build(config_file) { + match cmd::build(config_file, matches.value_of("base_url")) { Ok(()) => console::report_elapsed_time(start), Err(e) => { console::unravel_errors("Failed to build the site", &e);