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
This commit is contained in:
danda 2024-05-15 13:31:16 -07:00
parent 48966fa69d
commit df14092d61
10 changed files with 12 additions and 12 deletions

View File

@ -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<AppState>,
}

View File

@ -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(),
};

View File

@ -24,7 +24,6 @@ pub fn not_found_page(
}
let header = HeaderHtml {
site_name: "Neptune Explorer".to_string(),
state: state.clone(),
};

View File

@ -44,7 +44,6 @@ pub async fn utxo_page(
};
let header = HeaderHtml {
site_name: "Neptune Explorer".to_string(),
state: state.clone(),
};

View File

@ -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,

View File

@ -1,3 +1,3 @@
<header class="container">
<h1>{{self.site_name}} : {{self.state.network}}</h1>
<h1>{{self.state.config.site_name}} : {{self.state.network}}</h1>
</header>

View File

@ -2,7 +2,7 @@
<html>
<head>
<title>Neptune Block Explorer: Block Height {{self.block_info.height}}</title>
<title>{{self.header.state.config.site_name}}: Block Height {{self.block_info.height}}</title>
{{html_escaper::Trusted(include_str!(concat!(env!("CARGO_MANIFEST_DIR"),"/templates/web/html/components/head.html")))}}
</head>
@ -16,10 +16,10 @@
<!-- special_block_notice -->
%% if self.block_info.is_genesis {
<p>This is the Genesis Block</p>
<p>This is the genesis block</p>
%% }
%% if self.block_info.is_tip {
<p>This is the Latest Block (tip)</p>
<p>This is the latest block (tip)</p>
%% }
<table class="striped">

View File

@ -1,7 +1,7 @@
<html>
<head>
<title>Neptune Block Explorer: Not Found</title>
<title>{{self.header.state.config.site_name}}: Not Found</title>
{{html_escaper::Trusted(include_str!( concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/html/components/head.html")))}}
</head>

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>Neptune Block Explorer: (network: {{self.state.network}})</title>
<title>{{self.state.config.site_name}}: (network: {{self.state.network}})</title>
{{ html_escaper::Trusted(include_str!( concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/html/components/head.html"))) }}
<script>
function handle_submit(form) {
@ -23,7 +23,7 @@
<header class="container">
<h1>
<img src="/image/neptune-logo.png" align="right"/>
Neptune Block Explorer (network: {{self.state.network}})
{{self.state.config.site_name}} (network: {{self.state.network}})
</h1>
The blockchain tip is at height: {{self.tip_height}}
</header>

View File

@ -1,7 +1,7 @@
<html>
<head>
<title>Neptune Block Explorer: Utxo {{self.index}}</title>
<title>{{self.header.state.config.site_name}}: Utxo {{self.index}}</title>
{{html_escaper::Trusted(include_str!( concat!(env!("CARGO_MANIFEST_DIR"), "/templates/web/html/components/head.html")))}}
</head>