Ensure base path always starts and ends with /
The base path is an absolute path, so it should always start with /. Whenever it is used, it must also always be followed by at least one /, so baking that into the value makes sense. Finally, we can now deduplicate the / in case the base path is the root.
This commit is contained in:
parent
d5a41abaff
commit
6ed6ff1a36
4 changed files with 18 additions and 19 deletions
|
|
@ -22,7 +22,7 @@ mod default {
|
||||||
use std::{net::SocketAddr, time::Duration};
|
use std::{net::SocketAddr, time::Duration};
|
||||||
|
|
||||||
pub fn web_base() -> String {
|
pub fn web_base() -> String {
|
||||||
"".to_string()
|
"/".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn web_address() -> SocketAddr {
|
pub fn web_address() -> SocketAddr {
|
||||||
|
|
@ -138,13 +138,14 @@ impl ConfigFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn web_base(&self) -> String {
|
fn web_base(&self) -> String {
|
||||||
self.web
|
let mut base = self.web.base.clone();
|
||||||
.base
|
if !base.starts_with('/') {
|
||||||
.strip_prefix('/')
|
base.insert(0, '/');
|
||||||
.unwrap_or(&self.web.base)
|
}
|
||||||
.strip_suffix('/')
|
if !base.ends_with('/') {
|
||||||
.unwrap_or(&self.web.base)
|
base.push('/');
|
||||||
.to_string()
|
}
|
||||||
|
base
|
||||||
}
|
}
|
||||||
|
|
||||||
fn web_runner_token(&self) -> String {
|
fn web_runner_token(&self) -> String {
|
||||||
|
|
@ -204,6 +205,7 @@ pub struct RunnerServerConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
/// Always starts and ends with a `/`.
|
||||||
pub web_base: String,
|
pub web_base: String,
|
||||||
pub web_address: SocketAddr,
|
pub web_address: SocketAddr,
|
||||||
pub web_runner_token: String,
|
pub web_runner_token: String,
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,17 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>{% block title %}{% endblock %} - {{ base.repo_name }}</title>
|
<title>{% block title %}{% endblock %} - {{ base.repo_name }}</title>
|
||||||
<link rel="icon" href="/logo.svg">
|
<link rel="icon" href="{{ base.root }}logo.svg">
|
||||||
<link rel="stylesheet" href="{{ base.root }}/base.css" />
|
<link rel="stylesheet" href="{{ base.root }}base.css" />
|
||||||
{% block head %}{% endblock %}
|
{% block head %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<a href="{{ base.root }}/" {% if base.current=="index" %} class="current" {% endif %}>
|
<a href="{{ base.root }}" {% if base.current=="index" %} class="current" {% endif %}>
|
||||||
<img src="{{ base.root }}/logo.svg" alt="">{{ base.repo_name }}
|
<img src="{{ base.root }}logo.svg" alt="">{{ base.repo_name }}
|
||||||
</a>
|
</a>
|
||||||
<a href="{{ base.root }}/commit/" {% if base.current=="commit" %} class="current" {% endif %}>
|
<a href="{{ base.root }}queue/" {% if base.current=="queue" %} class="current" {% endif %}>
|
||||||
commit
|
|
||||||
</a>
|
|
||||||
<a href="{{ base.root }}/queue/" {% if base.current=="queue" %} class="current" {% endif %}>
|
|
||||||
queue
|
queue
|
||||||
</a>
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
{% for ref in tracked_refs %}
|
{% for ref in tracked_refs %}
|
||||||
<dt>{{ ref.name }}</dt>
|
<dt>{{ ref.name }}</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a href="{{ base.root }}/commit/{{ ref.hash }}">
|
<a href="{{ base.root }}commit/{{ ref.hash }}">
|
||||||
{% call util::commit_short(ref.short, ref.reachable) %}
|
{% call util::commit_short(ref.short, ref.reachable) %}
|
||||||
</a>
|
</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
{% for ref in untracked_refs %}
|
{% for ref in untracked_refs %}
|
||||||
<dt>{{ ref.name }}</dt>
|
<dt>{{ ref.name }}</dt>
|
||||||
<dd>
|
<dd>
|
||||||
<a href="{{ base.root }}/commit/{{ ref.hash }}">
|
<a href="{{ base.root }}commit/{{ ref.hash }}">
|
||||||
{% call util::commit_short(ref.short, ref.reachable) %}
|
{% call util::commit_short(ref.short, ref.reachable) %}
|
||||||
</a>
|
</a>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
{% for task in tasks %}
|
{% for task in tasks %}
|
||||||
<tr {% if task.odd %} class="odd" {% endif %}>
|
<tr {% if task.odd %} class="odd" {% endif %}>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ base.root }}/commit/{{ task.hash }}">
|
<a href="{{ base.root }}commit/{{ task.hash }}">
|
||||||
{% call util::commit_short(task.short, task.reachable) %}
|
{% call util::commit_short(task.short, task.reachable) %}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue