From b8ff9443777116152233f5304ff4e6fa086315a4 Mon Sep 17 00:00:00 2001 From: glyph Date: Mon, 28 Nov 2022 09:11:21 +0200 Subject: [PATCH] conditionally render status url based on run-mode --- peach-web/src/routes/home.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/peach-web/src/routes/home.rs b/peach-web/src/routes/home.rs index 4b085be..b70cd97 100644 --- a/peach-web/src/routes/home.rs +++ b/peach-web/src/routes/home.rs @@ -1,7 +1,7 @@ use maud::{html, PreEscaped}; use peach_lib::sbot::SbotStatus; -use crate::{templates, utils::theme}; +use crate::{templates, utils::theme, SERVER_CONFIG}; /// Read the state of the go-sbot process and define status-related /// elements accordingly. @@ -24,9 +24,23 @@ fn render_status_elements<'a>() -> (&'a str, &'a str, &'a str) { } } +/// Render the URL for the status element (icon / link). +/// +/// If the application is running in standalone mode then the element links +/// directly to the Scuttlebutt status page. If not, it links to the device +/// status page. +fn render_status_url<'a>() -> &'a str { + if SERVER_CONFIG.standalone_mode { + "/status/scuttlebutt" + } else { + "/status" + } +} + /// Home template builder. pub fn build_template() -> PreEscaped { let (circle_color, center_circle_text, circle_border) = render_status_elements(); + let status_url = render_status_url(); // render the home template html let home_template = html! { @@ -63,7 +77,7 @@ pub fn build_template() -> PreEscaped { } (PreEscaped("")) (PreEscaped("")) - a class="bottom-left" href="/status/scuttlebutt" title="Status" { + a class="bottom-left" href=(status_url) title="Status" { div class={ "circle circle-small border-circle-small " (circle_border) } { img class="icon-medium" src="/icons/heart-pulse.svg"; }