From df14092d61eeaec2633076213c511dadfc84066d Mon Sep 17 00:00:00 2001 From: danda Date: Wed, 15 May 2024 13:31:16 -0700 Subject: [PATCH] feat: make site name configurable Changes: + add Config::site_name, which defaults to "Neptune Explorer" + remove HeaderHtml::site_name + use Config::site_name in the html templates --- src/html/component/header.rs | 1 - src/html/page/block.rs | 1 - src/html/page/not_found.rs | 1 - src/html/page/utxo.rs | 1 - src/model/config.rs | 4 ++++ templates/web/html/components/header.html | 2 +- templates/web/html/page/block_info.html | 6 +++--- templates/web/html/page/not_found.html | 2 +- templates/web/html/page/root.html | 4 ++-- templates/web/html/page/utxo.html | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/html/component/header.rs b/src/html/component/header.rs index 2e07400..2a03279 100644 --- a/src/html/component/header.rs +++ b/src/html/component/header.rs @@ -5,6 +5,5 @@ use std::sync::Arc; #[derive(boilerplate::Boilerplate)] #[boilerplate(filename = "web/html/components/header.html")] pub struct HeaderHtml { - pub site_name: String, pub state: Arc, } diff --git a/src/html/page/block.rs b/src/html/page/block.rs index bab40e3..1cf23b8 100644 --- a/src/html/page/block.rs +++ b/src/html/page/block.rs @@ -40,7 +40,6 @@ pub async fn block_page_with_value( .map_err(|e| not_found_html_response(State(state.clone()), Some(e.to_string())))?; let header = HeaderHtml { - site_name: "Neptune Explorer".to_string(), state: state.clone(), }; diff --git a/src/html/page/not_found.rs b/src/html/page/not_found.rs index a1c04ee..3040a9e 100644 --- a/src/html/page/not_found.rs +++ b/src/html/page/not_found.rs @@ -24,7 +24,6 @@ pub fn not_found_page( } let header = HeaderHtml { - site_name: "Neptune Explorer".to_string(), state: state.clone(), }; diff --git a/src/html/page/utxo.rs b/src/html/page/utxo.rs index 8096f7d..9d02ff0 100644 --- a/src/html/page/utxo.rs +++ b/src/html/page/utxo.rs @@ -44,7 +44,6 @@ pub async fn utxo_page( }; let header = HeaderHtml { - site_name: "Neptune Explorer".to_string(), state: state.clone(), }; diff --git a/src/model/config.rs b/src/model/config.rs index e7cf162..3964d97 100644 --- a/src/model/config.rs +++ b/src/model/config.rs @@ -2,6 +2,10 @@ #[derive(Debug, clap::Parser, Clone)] #[clap(name = "neptune-explorer", about = "Neptune Block Explorer")] pub struct Config { + /// Sets the website name + #[clap(long, default_value = "Neptune Explorer", value_name = "site-name")] + pub site_name: String, + /// Sets the server address to connect to. #[clap(long, default_value = "9799", value_name = "PORT")] pub port: u16, diff --git a/templates/web/html/components/header.html b/templates/web/html/components/header.html index 6b4087e..8aff913 100644 --- a/templates/web/html/components/header.html +++ b/templates/web/html/components/header.html @@ -1,3 +1,3 @@
-

{{self.site_name}} : {{self.state.network}}

+

{{self.state.config.site_name}} : {{self.state.network}}

\ No newline at end of file diff --git a/templates/web/html/page/block_info.html b/templates/web/html/page/block_info.html index a876c4c..1e71a3a 100644 --- a/templates/web/html/page/block_info.html +++ b/templates/web/html/page/block_info.html @@ -2,7 +2,7 @@ - Neptune Block Explorer: Block Height {{self.block_info.height}} + {{self.header.state.config.site_name}}: Block Height {{self.block_info.height}} {{html_escaper::Trusted(include_str!(concat!(env!("CARGO_MANIFEST_DIR"),"/templates/web/html/components/head.html")))}} @@ -16,10 +16,10 @@ %% if self.block_info.is_genesis { -

This is the Genesis Block

+

This is the genesis block

%% } %% if self.block_info.is_tip { -

This is the Latest Block (tip)

+

This is the latest block (tip)

%% } diff --git a/templates/web/html/page/not_found.html b/templates/web/html/page/not_found.html index a69b7ed..5f497d5 100644 --- a/templates/web/html/page/not_found.html +++ b/templates/web/html/page/not_found.html @@ -1,7 +1,7 @@ - Neptune Block Explorer: Not Found + {{self.header.state.config.site_name}}: Not Found {{html_escaper::Trusted(include_str!( concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/html/components/head.html")))}} diff --git a/templates/web/html/page/root.html b/templates/web/html/page/root.html index 872196d..213c282 100644 --- a/templates/web/html/page/root.html +++ b/templates/web/html/page/root.html @@ -1,6 +1,6 @@ - Neptune Block Explorer: (network: {{self.state.network}}) + {{self.state.config.site_name}}: (network: {{self.state.network}}) {{ html_escaper::Trusted(include_str!( concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/html/components/head.html"))) }}