Skip to content

Commit

Permalink
Add new flag 'port_append' to give the ability to remove port from ba…
Browse files Browse the repository at this point in the history
…se url (#2003)
  • Loading branch information
ffrizzo authored and Keats committed Feb 16, 2023
1 parent a0f7dfe commit f7c67f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -302,6 +308,7 @@ pub fn serve(
base_url,
config_file,
include_drafts,
no_port_append,
None,
)?;
messages::report_elapsed_time(start);
Expand Down Expand Up @@ -502,6 +509,7 @@ pub fn serve(
base_url,
config_file,
include_drafts,
no_port_append,
ws_port,
) {
Ok((s, _)) => {
Expand Down
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f7c67f4

Please sign in to comment.