Add a base-url flag to the build command

This commit is contained in:
Vincent Prouillet 2017-10-05 10:56:13 +09:00
parent f26b9d53bd
commit 73797efe90
5 changed files with 14 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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

View file

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