add ability to hide individual routes

This commit is contained in:
Dustin Thomas 2026-01-30 12:22:11 -06:00
parent 1e950b9efc
commit 26e7119768
Signed by: cptlobster
GPG key ID: 33D607425C830B4C
5 changed files with 8 additions and 2 deletions

View file

@ -1,6 +1,7 @@
# Changelog
## Unreleased Changes
- Add support for hiding individual routes from route list.
## v0.1.3 (2025-09-09)
- Add support for having an array of paths match a single endpoint.

View file

@ -18,6 +18,7 @@ from = "dod([fs][0-9]{2})e([0-9]{3})"
# Capture groups can be replaced using numbered capture groups (`$1`, `$2`, ...)
to = "https://dod.cptlobster.dev/episodes/$1/$2"
using = "regex"
hidden = true
[[routes]]
from = "sub/path"

View file

@ -60,7 +60,9 @@ pub struct Route {
from: Multiable<String>,
to: String,
#[serde(default)]
using: MatcherType
using: MatcherType,
#[serde(default)]
hidden: bool
}
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]

View file

@ -29,7 +29,7 @@ use rocket_dyn_templates::{Template, tera::Tera, context};
async fn list_paths(cm: &State<ConfigManager>) -> Result<String, NoContent> {
let config = cm.get().await;
if config.hide_routes { return Err(NoContent) }
let all_routes = config.routes.iter().flat_map(|r: &Route| r.src()).collect::<Vec<String>>();
let all_routes = config.routes.iter().flat_map(|r: &Route| r.src()).filter(|r| !r.hidden).collect::<Vec<String>>();
if all_routes.is_empty() { Err(NoContent) } else {
Ok(all_routes.into_iter().map(|a| format!("/{}", a)).collect::<Vec<String>>().join("\n"))
}

View file

@ -10,6 +10,7 @@
</p>
<ul>
{%- for route in config.routes %}
{%- if not route.hidden %}
<li>
{%- if route.using == "regex" %}
{% if route.from is iterable %}
@ -26,6 +27,7 @@
{%- endif %}
({{ route.using }})
</li>
{%- endif %}
{%- else %}
<li>No routes configured.</li>
{%- endfor %}