From 26e7119768871ca596869467a440cd40e4b8461f Mon Sep 17 00:00:00 2001 From: Dustin Thomas Date: Fri, 30 Jan 2026 12:22:11 -0600 Subject: [PATCH] add ability to hide individual routes --- CHANGELOG.md | 1 + sg1.toml | 1 + src/config.rs | 4 +++- src/main.rs | 2 +- templates/main.html.tera | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45033ea..1895e43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/sg1.toml b/sg1.toml index 2f41576..af263cf 100644 --- a/sg1.toml +++ b/sg1.toml @@ -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" diff --git a/src/config.rs b/src/config.rs index 7da1160..8f076c9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -60,7 +60,9 @@ pub struct Route { from: Multiable, to: String, #[serde(default)] - using: MatcherType + using: MatcherType, + #[serde(default)] + hidden: bool } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/src/main.rs b/src/main.rs index 5a69966..56a2cd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,7 @@ use rocket_dyn_templates::{Template, tera::Tera, context}; async fn list_paths(cm: &State) -> Result { 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::>(); + let all_routes = config.routes.iter().flat_map(|r: &Route| r.src()).filter(|r| !r.hidden).collect::>(); if all_routes.is_empty() { Err(NoContent) } else { Ok(all_routes.into_iter().map(|a| format!("/{}", a)).collect::>().join("\n")) } diff --git a/templates/main.html.tera b/templates/main.html.tera index fc97a84..f1e25c1 100644 --- a/templates/main.html.tera +++ b/templates/main.html.tera @@ -10,6 +10,7 @@

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