diff --git a/quickpeep.sample.ron b/quickpeep.sample.ron index 83dd994..7843c5d 100644 --- a/quickpeep.sample.ron +++ b/quickpeep.sample.ron @@ -63,6 +63,8 @@ ], sqlite_db_path: "data/dev_qp_web.sqlite3", + + public_base: "http://127.0.0.1:9001", ), // Index (indexer, web) diff --git a/quickpeep/src/bin/quickpeep.rs b/quickpeep/src/bin/quickpeep.rs index dc4b6ab..fc09602 100644 --- a/quickpeep/src/bin/quickpeep.rs +++ b/quickpeep/src/bin/quickpeep.rs @@ -7,6 +7,7 @@ use env_logger::Env; use log::info; use quickpeep::config::WebConfig; use quickpeep::web::icon_retrieval::retrieve_icon; +use quickpeep::web::metadata::get_opensearch_xml; use quickpeep::web::searcher::{search_root, search_search}; use quickpeep::web::seed_collector::{seed_collection_root, seed_collection_root_post}; use quickpeep::web::IndexAccess; @@ -76,6 +77,7 @@ async fn main() -> anyhow::Result<()> { .route("/", get(search_root)) .route("/search", get(search_search)) .route("/icon.webp", get(retrieve_icon)) + .route("/opensearch.xml", get(get_opensearch_xml)) .layer(Extension(web_config)) .layer(Extension(pool)) .layer(Extension(index_access)) diff --git a/quickpeep/src/config.rs b/quickpeep/src/config.rs index 80b4072..b985af9 100644 --- a/quickpeep/src/config.rs +++ b/quickpeep/src/config.rs @@ -31,6 +31,10 @@ pub struct WebOnlyConfig { pub sqlite_db_path: PathBuf, /// Name, URL pairs pub contact: Vec<(String, String)>, + + /// URL prefix for QuickPeep. Should include protocol. No trailing slash. + /// Example: https://quickpeep.net + pub public_base: String, } impl WebConfig { diff --git a/quickpeep/src/web.rs b/quickpeep/src/web.rs index fc0e2c5..761f37a 100644 --- a/quickpeep/src/web.rs +++ b/quickpeep/src/web.rs @@ -2,6 +2,7 @@ use quickpeep_index::backend::Backend; use std::sync::Arc; pub mod icon_retrieval; +pub mod metadata; pub mod searcher; pub mod seed_collector; diff --git a/quickpeep/src/web/metadata.rs b/quickpeep/src/web/metadata.rs new file mode 100644 index 0000000..7e447d4 --- /dev/null +++ b/quickpeep/src/web/metadata.rs @@ -0,0 +1,28 @@ +use crate::config::WebConfig; +use axum::extract::Extension; +use axum::response::{IntoResponse, Response}; + +pub async fn get_opensearch_xml(Extension(web_config): Extension) -> impl IntoResponse { + let public_base = &web_config.web.public_base; + let formatted = format!( + r#" + + QuickPeep + small-scale web search engine + UTF-8 + {public_base}/favicon.ico + + + "# + ); + + // Extras for the future: + // + // [https://example.com/search] + + Response::builder() + .header("content-type", "application/opensearchdescription+xml") + .body(formatted.into_response()) + .unwrap() +}