add option to change site name in config and cleanup
This commit is contained in:
parent
09435e4d86
commit
cd2827b9fc
@ -5,7 +5,7 @@ api = false
|
|||||||
|
|
||||||
[ui]
|
[ui]
|
||||||
# engine_list_separator = true
|
# engine_list_separator = true
|
||||||
# version_info = true
|
# show_version_info = true
|
||||||
# stylesheet_url = "/themes/catppuccin-mocha.css"
|
# stylesheet_url = "/themes/catppuccin-mocha.css"
|
||||||
|
|
||||||
[engines]
|
[engines]
|
||||||
|
@ -39,19 +39,17 @@ impl Config {
|
|||||||
pub struct UiConfig {
|
pub struct UiConfig {
|
||||||
pub show_engine_list_separator: bool,
|
pub show_engine_list_separator: bool,
|
||||||
pub show_version_info: bool,
|
pub show_version_info: bool,
|
||||||
|
pub site_name: String,
|
||||||
pub stylesheet_url: Option<String>,
|
pub stylesheet_url: Option<String>,
|
||||||
pub stylesheet_str: Option<String>,
|
pub stylesheet_str: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Default)]
|
#[derive(Deserialize, Debug, Default)]
|
||||||
pub struct PartialUiConfig {
|
pub struct PartialUiConfig {
|
||||||
#[serde(default)]
|
|
||||||
pub show_engine_list_separator: Option<bool>,
|
pub show_engine_list_separator: Option<bool>,
|
||||||
#[serde(default)]
|
|
||||||
pub show_version_info: Option<bool>,
|
pub show_version_info: Option<bool>,
|
||||||
#[serde(default)]
|
pub site_name: Option<String>,
|
||||||
pub stylesheet_url: Option<String>,
|
pub stylesheet_url: Option<String>,
|
||||||
#[serde(default)]
|
|
||||||
pub stylesheet_str: Option<String>,
|
pub stylesheet_str: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +59,9 @@ impl UiConfig {
|
|||||||
.show_engine_list_separator
|
.show_engine_list_separator
|
||||||
.unwrap_or(self.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.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_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 struct PartialImageSearchConfig {
|
||||||
pub enabled: Option<bool>,
|
pub enabled: Option<bool>,
|
||||||
pub show_engines: Option<bool>,
|
pub show_engines: Option<bool>,
|
||||||
#[serde(default)]
|
pub proxy: Option<PartialImageProxyConfig>,
|
||||||
pub proxy: PartialImageProxyConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageSearchConfig {
|
impl ImageSearchConfig {
|
||||||
pub fn overlay(&mut self, partial: PartialImageSearchConfig) {
|
pub fn overlay(&mut self, partial: PartialImageSearchConfig) {
|
||||||
self.enabled = partial.enabled.unwrap_or(self.enabled);
|
self.enabled = partial.enabled.unwrap_or(self.enabled);
|
||||||
self.show_engines = partial.show_engines.unwrap_or(self.show_engines);
|
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)]
|
#[derive(Deserialize, Clone, Debug, Default)]
|
||||||
pub struct PartialEngineConfig {
|
pub struct PartialEngineConfig {
|
||||||
#[serde(default)]
|
|
||||||
pub enabled: Option<bool>,
|
pub enabled: Option<bool>,
|
||||||
|
|
||||||
#[serde(default)]
|
|
||||||
pub weight: Option<f64>,
|
pub weight: Option<f64>,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub extra: toml::Table,
|
pub extra: toml::Table,
|
||||||
@ -209,6 +205,7 @@ impl Default for Config {
|
|||||||
ui: UiConfig {
|
ui: UiConfig {
|
||||||
show_engine_list_separator: false,
|
show_engine_list_separator: false,
|
||||||
show_version_info: false,
|
show_version_info: false,
|
||||||
|
site_name: "metasearch".to_string(),
|
||||||
stylesheet_url: None,
|
stylesheet_url: None,
|
||||||
stylesheet_str: None,
|
stylesheet_str: None,
|
||||||
},
|
},
|
||||||
|
@ -20,7 +20,7 @@ pub async fn index(State(config): State<Arc<Config>>) -> impl IntoResponse {
|
|||||||
head {
|
head {
|
||||||
meta charset="UTF-8";
|
meta charset="UTF-8";
|
||||||
meta name="viewport" content="width=device-width, initial-scale=1.0";
|
meta name="viewport" content="width=device-width, initial-scale=1.0";
|
||||||
title { "metasearch" }
|
title { {(config.ui.site_name)} }
|
||||||
link rel="stylesheet" href="/style.css";
|
link rel="stylesheet" href="/style.css";
|
||||||
@if let Some(stylesheet_url) = &config.ui.stylesheet_url {
|
@if let Some(stylesheet_url) = &config.ui.stylesheet_url {
|
||||||
link rel="stylesheet" href=(stylesheet_url);
|
link rel="stylesheet" href=(stylesheet_url);
|
||||||
@ -33,7 +33,7 @@ pub async fn index(State(config): State<Arc<Config>>) -> impl IntoResponse {
|
|||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
div."main-container" {
|
div."main-container" {
|
||||||
h1 { "metasearch" }
|
h1 { {(config.ui.site_name)} }
|
||||||
form."search-form" action="/search" method="get" {
|
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="text" name="q" placeholder="Search" id="search-input" autofocus onfocus="this.select()" autocomplete="off";
|
||||||
input type="submit" value="Search";
|
input type="submit" value="Search";
|
||||||
|
@ -2,6 +2,7 @@ use axum::{
|
|||||||
http::{header, HeaderMap},
|
http::{header, HeaderMap},
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
};
|
};
|
||||||
|
use maud::{html, PreEscaped};
|
||||||
|
|
||||||
pub async fn route(headers: HeaderMap) -> impl IntoResponse {
|
pub async fn route(headers: HeaderMap) -> impl IntoResponse {
|
||||||
let host = headers
|
let host = headers
|
||||||
@ -14,16 +15,15 @@ pub async fn route(headers: HeaderMap) -> impl IntoResponse {
|
|||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
"application/opensearchdescription+xml",
|
"application/opensearchdescription+xml",
|
||||||
)],
|
)],
|
||||||
format!(
|
html! {
|
||||||
r#"<?xml version="1.0" encoding="utf-8"?>
|
(PreEscaped(r#"<?xml version="1.0" encoding="utf-8"?>"#))
|
||||||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" {
|
||||||
<ShortName>metasearch</ShortName>
|
ShortName { "metasearch" }
|
||||||
<Description>Search metasearch</Description>
|
Description { "Search metasearch" }
|
||||||
<InputEncoding>UTF-8</InputEncoding>
|
InputEncoding { "UTF-8" }
|
||||||
<Url type="text/html" method="get" template="https://{host}/search?q={{searchTerms}}" />
|
Url type="text/html" method="get" template=(format!("https://{host}/search?q={{searchTerms}}")) {}
|
||||||
<Url type="application/x-suggestions+json" method="get"
|
Url type="application/x-suggestions+json" method="get" template=(format!("https://{host}/autocomplete?q={{searchTerms}}")) {}
|
||||||
template="https://{host}/autocomplete?q={{searchTerms}}" />
|
}
|
||||||
</OpenSearchDescription>"#
|
}.into_string(),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,8 @@ fn render_beginning_of_html(search: &SearchQuery) -> String {
|
|||||||
meta name="viewport" content="width=device-width, initial-scale=1.0";
|
meta name="viewport" content="width=device-width, initial-scale=1.0";
|
||||||
title {
|
title {
|
||||||
(search.query)
|
(search.query)
|
||||||
" - metasearch"
|
" - "
|
||||||
|
(search.config.ui.site_name)
|
||||||
}
|
}
|
||||||
link rel="stylesheet" href="/style.css";
|
link rel="stylesheet" href="/style.css";
|
||||||
@if let Some(stylesheet_url) = &search.config.ui.stylesheet_url {
|
@if let Some(stylesheet_url) = &search.config.ui.stylesheet_url {
|
||||||
|
Loading…
Reference in New Issue
Block a user