add option to change site name in config and cleanup

This commit is contained in:
mat 2024-06-29 02:13:03 -05:00
parent 09435e4d86
commit cd2827b9fc
5 changed files with 23 additions and 25 deletions

View File

@ -5,7 +5,7 @@ api = false
[ui]
# engine_list_separator = true
# version_info = true
# show_version_info = true
# stylesheet_url = "/themes/catppuccin-mocha.css"
[engines]

View File

@ -39,19 +39,17 @@ impl Config {
pub struct UiConfig {
pub show_engine_list_separator: bool,
pub show_version_info: bool,
pub site_name: String,
pub stylesheet_url: Option<String>,
pub stylesheet_str: Option<String>,
}
#[derive(Deserialize, Debug, Default)]
pub struct PartialUiConfig {
#[serde(default)]
pub show_engine_list_separator: Option<bool>,
#[serde(default)]
pub show_version_info: Option<bool>,
#[serde(default)]
pub site_name: Option<String>,
pub stylesheet_url: Option<String>,
#[serde(default)]
pub stylesheet_str: Option<String>,
}
@ -61,7 +59,9 @@ impl UiConfig {
.show_engine_list_separator
.unwrap_or(self.show_engine_list_separator);
self.show_version_info = partial.show_version_info.unwrap_or(self.show_version_info);
self.site_name = partial.site_name.unwrap_or(self.site_name.clone());
self.stylesheet_url = partial.stylesheet_url.or(self.stylesheet_url.clone());
self.stylesheet_str = partial.stylesheet_str.or(self.stylesheet_str.clone());
}
}
@ -76,15 +76,14 @@ pub struct ImageSearchConfig {
pub struct PartialImageSearchConfig {
pub enabled: Option<bool>,
pub show_engines: Option<bool>,
#[serde(default)]
pub proxy: PartialImageProxyConfig,
pub proxy: Option<PartialImageProxyConfig>,
}
impl ImageSearchConfig {
pub fn overlay(&mut self, partial: PartialImageSearchConfig) {
self.enabled = partial.enabled.unwrap_or(self.enabled);
self.show_engines = partial.show_engines.unwrap_or(self.show_engines);
self.proxy.overlay(partial.proxy);
self.proxy.overlay(partial.proxy.unwrap_or_default());
}
}
@ -164,10 +163,7 @@ pub struct EngineConfig {
#[derive(Deserialize, Clone, Debug, Default)]
pub struct PartialEngineConfig {
#[serde(default)]
pub enabled: Option<bool>,
#[serde(default)]
pub weight: Option<f64>,
#[serde(flatten)]
pub extra: toml::Table,
@ -209,6 +205,7 @@ impl Default for Config {
ui: UiConfig {
show_engine_list_separator: false,
show_version_info: false,
site_name: "metasearch".to_string(),
stylesheet_url: None,
stylesheet_str: None,
},

View File

@ -20,7 +20,7 @@ pub async fn index(State(config): State<Arc<Config>>) -> impl IntoResponse {
head {
meta charset="UTF-8";
meta name="viewport" content="width=device-width, initial-scale=1.0";
title { "metasearch" }
title { {(config.ui.site_name)} }
link rel="stylesheet" href="/style.css";
@if let Some(stylesheet_url) = &config.ui.stylesheet_url {
link rel="stylesheet" href=(stylesheet_url);
@ -33,7 +33,7 @@ pub async fn index(State(config): State<Arc<Config>>) -> impl IntoResponse {
}
body {
div."main-container" {
h1 { "metasearch" }
h1 { {(config.ui.site_name)} }
form."search-form" action="/search" method="get" {
input type="text" name="q" placeholder="Search" id="search-input" autofocus onfocus="this.select()" autocomplete="off";
input type="submit" value="Search";

View File

@ -2,6 +2,7 @@ use axum::{
http::{header, HeaderMap},
response::IntoResponse,
};
use maud::{html, PreEscaped};
pub async fn route(headers: HeaderMap) -> impl IntoResponse {
let host = headers
@ -14,16 +15,15 @@ pub async fn route(headers: HeaderMap) -> impl IntoResponse {
header::CONTENT_TYPE,
"application/opensearchdescription+xml",
)],
format!(
r#"<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>metasearch</ShortName>
<Description>Search metasearch</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="get" template="https://{host}/search?q={{searchTerms}}" />
<Url type="application/x-suggestions+json" method="get"
template="https://{host}/autocomplete?q={{searchTerms}}" />
</OpenSearchDescription>"#
),
html! {
(PreEscaped(r#"<?xml version="1.0" encoding="utf-8"?>"#))
OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" {
ShortName { "metasearch" }
Description { "Search metasearch" }
InputEncoding { "UTF-8" }
Url type="text/html" method="get" template=(format!("https://{host}/search?q={{searchTerms}}")) {}
Url type="application/x-suggestions+json" method="get" template=(format!("https://{host}/autocomplete?q={{searchTerms}}")) {}
}
}.into_string(),
)
}

View File

@ -29,7 +29,8 @@ fn render_beginning_of_html(search: &SearchQuery) -> String {
meta name="viewport" content="width=device-width, initial-scale=1.0";
title {
(search.query)
" - metasearch"
" - "
(search.config.ui.site_name)
}
link rel="stylesheet" href="/style.css";
@if let Some(stylesheet_url) = &search.config.ui.stylesheet_url {