diff --git a/config-default.toml b/config-default.toml index 4e903ec..0a75fb6 100644 --- a/config-default.toml +++ b/config-default.toml @@ -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] diff --git a/src/config.rs b/src/config.rs index 98d0b80..1808fab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, pub stylesheet_str: Option, } #[derive(Deserialize, Debug, Default)] pub struct PartialUiConfig { - #[serde(default)] pub show_engine_list_separator: Option, - #[serde(default)] pub show_version_info: Option, - #[serde(default)] + pub site_name: Option, pub stylesheet_url: Option, - #[serde(default)] pub stylesheet_str: Option, } @@ -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, pub show_engines: Option, - #[serde(default)] - pub proxy: PartialImageProxyConfig, + pub proxy: Option, } 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, - - #[serde(default)] pub weight: Option, #[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, }, diff --git a/src/web/index.rs b/src/web/index.rs index b38ea6d..53b11c9 100644 --- a/src/web/index.rs +++ b/src/web/index.rs @@ -20,7 +20,7 @@ pub async fn index(State(config): State>) -> 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>) -> 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"; diff --git a/src/web/opensearch.rs b/src/web/opensearch.rs index 690a858..f46d38e 100644 --- a/src/web/opensearch.rs +++ b/src/web/opensearch.rs @@ -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#" - - metasearch - Search metasearch - UTF-8 - - - "# - ), + html! { + (PreEscaped(r#""#)) + 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(), ) } diff --git a/src/web/search.rs b/src/web/search.rs index 350b722..2750f34 100644 --- a/src/web/search.rs +++ b/src/web/search.rs @@ -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 {