Add new flag 'port_append' to give the ability to remove port from base url (#2003)
This commit is contained in:
parent
a0f7dfed97
commit
f7c67f4fd0
@ -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
|
||||
|
@ -241,6 +241,7 @@ fn create_new_site(
|
||||
base_url: &str,
|
||||
config_file: &Path,
|
||||
include_drafts: bool,
|
||||
no_port_append: bool,
|
||||
ws_port: Option<u16>,
|
||||
) -> 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, _)) => {
|
||||
|
12
src/main.rs
12
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user