diff --git a/src/cli.rs b/src/cli.rs index 504d5a424b..8d6629cd74 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -80,6 +80,10 @@ pub enum Command { /// Only rebuild the minimum on change - useful when working on a specific page/section #[clap(short = 'f', long)] fast: bool, + + /// Default append port to the base url. + #[clap(long, default_value_t = false)] + no_port_append: bool, }, /// Try to build the project without rendering it. Checks links diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 0242a9a075..785f9f15a3 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -241,6 +241,7 @@ fn create_new_site( base_url: &str, config_file: &Path, include_drafts: bool, + no_port_append: bool, ws_port: Option, ) -> Result<(Site, String)> { SITE_CONTENT.write().unwrap().clear(); @@ -251,7 +252,11 @@ fn create_new_site( let base_url = if base_url == "/" { String::from("/") } else { - let base_address = format!("{}:{}", base_url, interface_port); + let base_address = if no_port_append { + base_url.to_string() + } else { + format!("{}:{}", base_url, interface_port) + }; if site.config.base_url.ends_with('/') { format!("http://{}/", base_address) @@ -291,6 +296,7 @@ pub fn serve( open: bool, include_drafts: bool, fast_rebuild: bool, + no_port_append: bool, utc_offset: UtcOffset, ) -> Result<()> { let start = Instant::now(); @@ -302,6 +308,7 @@ pub fn serve( base_url, config_file, include_drafts, + no_port_append, None, )?; messages::report_elapsed_time(start); @@ -502,6 +509,7 @@ pub fn serve( base_url, config_file, include_drafts, + no_port_append, ws_port, ) { Ok((s, _)) => { diff --git a/src/main.rs b/src/main.rs index 1b9fb3773e..05542e6149 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,16 @@ fn main() { } } } - Command::Serve { interface, mut port, output_dir, base_url, drafts, open, fast } => { + Command::Serve { + interface, + mut port, + output_dir, + base_url, + drafts, + open, + fast, + no_port_append, + } => { if port != 1111 && !port_is_available(port) { console::error("The requested port is not available"); std::process::exit(1); @@ -83,6 +92,7 @@ fn main() { open, drafts, fast, + no_port_append, UtcOffset::current_local_offset().unwrap_or(UtcOffset::UTC), ) { messages::unravel_errors("Failed to serve the site", &e);