Hide icons that don't exist
This commit is contained in:
parent
e2a4835536
commit
99fcbf77f6
@ -4,7 +4,9 @@ use crate::webutil::{internal_error, TemplatedHtml};
|
|||||||
use askama::Template;
|
use askama::Template;
|
||||||
use axum::extract::{Extension, Query};
|
use axum::extract::{Extension, Query};
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
|
use quickpeep_index::auxiliary::icon_store::IconStore;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone, Template)]
|
#[derive(Clone, Template)]
|
||||||
#[template(path = "search.html.askama")]
|
#[template(path = "search.html.askama")]
|
||||||
@ -17,7 +19,7 @@ pub struct SearchTemplate {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SearchResult {
|
pub struct SearchResult {
|
||||||
pub favicon_url: String,
|
pub favicon_url: Option<String>,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub excerpt: String,
|
pub excerpt: String,
|
||||||
@ -49,8 +51,9 @@ pub async fn search_search(
|
|||||||
web_config: Extension<WebConfig>,
|
web_config: Extension<WebConfig>,
|
||||||
index_access: Extension<IndexAccess>,
|
index_access: Extension<IndexAccess>,
|
||||||
params: Query<QueryParameters>,
|
params: Query<QueryParameters>,
|
||||||
|
icon_store: Extension<Arc<IconStore>>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
search_search_inner(web_config, index_access, params)
|
search_search_inner(web_config, index_access, params, icon_store)
|
||||||
.await
|
.await
|
||||||
.map_err(internal_error)
|
.map_err(internal_error)
|
||||||
}
|
}
|
||||||
@ -59,14 +62,22 @@ pub async fn search_search_inner(
|
|||||||
Extension(web_config): Extension<WebConfig>,
|
Extension(web_config): Extension<WebConfig>,
|
||||||
Extension(index_access): Extension<IndexAccess>,
|
Extension(index_access): Extension<IndexAccess>,
|
||||||
Query(params): Query<QueryParameters>,
|
Query(params): Query<QueryParameters>,
|
||||||
|
Extension(icon_store): Extension<Arc<IconStore>>,
|
||||||
) -> anyhow::Result<impl IntoResponse> {
|
) -> anyhow::Result<impl IntoResponse> {
|
||||||
let raw_results = index_access.backend.query(params.q.clone())?;
|
let raw_results = index_access.backend.query(params.q.clone())?;
|
||||||
|
|
||||||
let mut results = Vec::with_capacity(raw_results.len());
|
let mut results = Vec::with_capacity(raw_results.len());
|
||||||
|
|
||||||
|
let txn = icon_store.env.ro_txn()?;
|
||||||
|
|
||||||
for search_doc in raw_results {
|
for search_doc in raw_results {
|
||||||
|
let favicon_url_hash: [u8; 8] = search_doc.favicon_url_hash.to_le_bytes();
|
||||||
|
let favicon_url = icon_store
|
||||||
|
.icons
|
||||||
|
.get(&txn, &favicon_url_hash)?
|
||||||
|
.map(|_| format!("{:016x}", search_doc.favicon_url_hash));
|
||||||
results.push(SearchResult {
|
results.push(SearchResult {
|
||||||
favicon_url: format!("{:16x}", search_doc.favicon_url_hash),
|
favicon_url,
|
||||||
url: search_doc.url,
|
url: search_doc.url,
|
||||||
title: search_doc.title,
|
title: search_doc.title,
|
||||||
excerpt: search_doc.excerpt,
|
excerpt: search_doc.excerpt,
|
||||||
|
@ -42,7 +42,9 @@
|
|||||||
<ul class="search_results">
|
<ul class="search_results">
|
||||||
{%- for result in results %}
|
{%- for result in results %}
|
||||||
<li>
|
<li>
|
||||||
<img src="/icon.webp?b={{ result.favicon_url }}">
|
{%- if result.favicon_url.is_some() -%}
|
||||||
|
<img src="/icon.webp?b={{ result.favicon_url.as_ref().unwrap() }}">
|
||||||
|
{%- endif -%}
|
||||||
<div class="result_title"><a href="{{ result.url }}" rel="nofollow noreferrer">{{ result.title }}</a></div>
|
<div class="result_title"><a href="{{ result.url }}" rel="nofollow noreferrer">{{ result.title }}</a></div>
|
||||||
<div class="result_excerpt">
|
<div class="result_excerpt">
|
||||||
{{- result.excerpt|safe -}}
|
{{- result.excerpt|safe -}}
|
||||||
|
Loading…
Reference in New Issue
Block a user