Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new flag 'no-port-append' to give the ability to remove port from base url #2003

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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