Initial favicon add

This commit is contained in:
partisan 2025-04-28 20:03:33 +02:00
parent 6445be87a9
commit bc89f5b819
8 changed files with 755 additions and 21 deletions

35
text.go
View file

@ -33,7 +33,13 @@ func initTextEngines() {
func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string, page int) {
startTime := time.Now()
cacheKey := CacheKey{Query: query, Page: page, Safe: settings.SafeSearch == "active", Lang: settings.SearchLanguage, Type: "text"}
cacheKey := CacheKey{
Query: query,
Page: page,
Safe: settings.SafeSearch == "active",
Lang: settings.SearchLanguage,
Type: "text",
}
combinedResults := getTextResultsFromCacheOrFetch(cacheKey, query, settings.SafeSearch, settings.SearchLanguage, page)
hasPrevPage := page > 1
@ -46,13 +52,32 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
elapsedTime := time.Since(startTime)
// Prepare the data to pass to the template
// Prepare safe decorated results
type DecoratedResult struct {
TextSearchResult
FaviconURL string
PrettyLink LinkParts
}
var decoratedResults []DecoratedResult
for _, r := range combinedResults {
if r.URL == "" {
continue
}
decoratedResults = append(decoratedResults, DecoratedResult{
TextSearchResult: r,
FaviconURL: getFaviconProxyURL("", r.URL),
PrettyLink: FormatLinkHTML(r.URL),
})
}
data := map[string]interface{}{
"Results": combinedResults,
"Results": decoratedResults,
"Query": query,
"Fetched": FormatElapsedTime(elapsedTime),
"Page": page,
"HasPrevPage": page > 1,
"HasPrevPage": hasPrevPage,
"HasNextPage": len(combinedResults) >= 50,
"NoResults": len(combinedResults) == 0,
"LanguageOptions": languageOptions,
@ -63,7 +88,7 @@ func HandleTextSearch(w http.ResponseWriter, settings UserSettings, query string
"Trans": Translate,
}
// Render the template without measuring time
// Render the template
renderTemplate(w, "text.html", data)
}