Enables setting base-url to / for relative URLs in serve mode (#1853)
Having to change the base URL to whatever ngrok URL was provisioned for me was frustrating. This patch enables setting it to `/`, which will then make the `get_url()` function simply return `/`.
This commit is contained in:
parent
beb93f2b0a
commit
f7f5545bdc
|
@ -74,7 +74,7 @@ You can also specify different addresses for the interface and base_url using `-
|
|||
|
||||
> By default, devices from the local network **won't** be able to access the served pages. This may be of importance when you want to test page interaction and layout on your mobile device or tablet. If you set the interface to `0.0.0.0` however, devices from your local network will be able to access the served pages by requesting the local ip-address of the machine serving the pages and port used.
|
||||
>
|
||||
> In order to have everything work correctly, you might also have to alter the `base-url` flag to your local ip.
|
||||
> In order to have everything work correctly, you might also have to alter the `base-url` flag to your local ip or set it to `/` to use server-base relative paths.
|
||||
|
||||
Use the `--open` flag to automatically open the locally hosted instance in your
|
||||
web browser.
|
||||
|
@ -87,6 +87,7 @@ $ zola serve --port 2000
|
|||
$ zola serve --interface 0.0.0.0
|
||||
$ zola serve --interface 0.0.0.0 --port 2000
|
||||
$ zola serve --interface 0.0.0.0 --base-url 127.0.0.1
|
||||
$ zola serve --interface 0.0.0.0 --base-url /
|
||||
$ zola serve --interface 0.0.0.0 --port 2000 --output-dir www/public
|
||||
$ zola serve --open
|
||||
```
|
||||
|
|
|
@ -246,14 +246,18 @@ fn create_new_site(
|
|||
SITE_CONTENT.write().unwrap().clear();
|
||||
|
||||
let mut site = Site::new(root_dir, config_file)?;
|
||||
|
||||
let base_address = format!("{}:{}", base_url, interface_port);
|
||||
let address = format!("{}:{}", interface, interface_port);
|
||||
|
||||
let base_url = if site.config.base_url.ends_with('/') {
|
||||
let base_url = if base_url == "/" {
|
||||
String::from("/")
|
||||
} else {
|
||||
let base_address = format!("{}:{}", base_url, interface_port);
|
||||
|
||||
if site.config.base_url.ends_with('/') {
|
||||
format!("http://{}/", base_address)
|
||||
} else {
|
||||
format!("http://{}", base_address)
|
||||
}
|
||||
};
|
||||
|
||||
site.enable_serve_mode();
|
||||
|
|
Loading…
Reference in New Issue