fix broken source code url and add text on no results

This commit is contained in:
mat 2024-03-30 22:16:38 -05:00
parent 1e6a5278c7
commit 6a6bbfcb51
2 changed files with 40 additions and 18 deletions

View File

@ -1,20 +1,33 @@
<!-- source code: https://https://git.matdoes.dev/mat/metasearch2 -->
<!-- source code: https://github.com/mat-1/metasearch2 -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>metasearch</title>
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/style.css" />
<script src="/script.js" defer></script>
<link rel="search" type="application/opensearchdescription+xml" title="metasearch" href="/opensearch.xml"/>
<link
rel="search"
type="application/opensearchdescription+xml"
title="metasearch"
href="/opensearch.xml"
/>
</head>
<body>
<div class="main-container">
<h1>metasearch</h1>
<form action="/search" method="get" class="search-form">
<input type="text" name="q" placeholder="Search" id="search-input" autofocus onfocus="this.select()" autocomplete="off">
<input type="submit" value="Search">
<input
type="text"
name="q"
placeholder="Search"
id="search-input"
autofocus
onfocus="this.select()"
autocomplete="off"
/>
<input type="submit" value="Search" />
</form>
</div>
</body>

View File

@ -95,7 +95,7 @@ fn render_featured_snippet(featured_snippet: &engines::FeaturedSnippet) -> Strin
fn render_results(response: Response) -> String {
let mut html = String::new();
if let Some(infobox) = response.infobox {
if let Some(infobox) = &response.infobox {
html.push_str(&format!(
r#"<div class="infobox">{infobox_html}{engines_html}</div>"#,
infobox_html = &infobox.html,
@ -103,19 +103,28 @@ fn render_results(response: Response) -> String {
));
}
if let Some(answer) = response.answer {
if let Some(answer) = &response.answer {
html.push_str(&format!(
r#"<div class="answer">{answer_html}{engines_html}</div>"#,
answer_html = &answer.html,
engines_html = render_engine_list(&[answer.engine])
));
}
if let Some(featured_snippet) = response.featured_snippet {
if let Some(featured_snippet) = &response.featured_snippet {
html.push_str(&render_featured_snippet(&featured_snippet));
}
for result in &response.search_results {
html.push_str(&render_search_result(result));
}
if response.infobox.is_none()
&& response.answer.is_none()
&& response.featured_snippet.is_none()
&& response.search_results.is_empty()
{
html.push_str(r#"<p>No results.</p>"#);
}
html
}