mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-15 01:10:35 +00:00
Feature: search suggestions for search and quick launch (#2775)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
f0635db51d
commit
d5af7eda63
8 changed files with 269 additions and 92 deletions
23
src/pages/api/search/searchSuggestion.js
Normal file
23
src/pages/api/search/searchSuggestion.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { searchProviders } from "components/widgets/search/search";
|
||||
import cachedFetch from "utils/proxy/cached-fetch";
|
||||
import { widgetsFromConfig } from "utils/config/widget-helpers";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { query, providerName } = req.query;
|
||||
|
||||
const provider = Object.values(searchProviders).find(({ name }) => name === providerName);
|
||||
|
||||
if (provider.name === "Custom") {
|
||||
const widgets = await widgetsFromConfig();
|
||||
const searchWidget = widgets.find((w) => w.type === "search");
|
||||
|
||||
provider.url = searchWidget.options.url;
|
||||
provider.suggestionUrl = searchWidget.options.suggestionUrl;
|
||||
}
|
||||
|
||||
if (!provider.suggestionUrl) {
|
||||
return res.json([query, []]); // Responde with the same array format but with no suggestions.
|
||||
}
|
||||
|
||||
return res.send(await cachedFetch(`${provider.suggestionUrl}${encodeURIComponent(query)}`, 5));
|
||||
}
|
|
@ -211,12 +211,12 @@ function Home({ initialSettings }) {
|
|||
// if search provider is a list, try to retrieve from localstorage, fall back to the first
|
||||
searchProvider = getStoredProvider() ?? searchProviders[searchWidget.options.provider[0]];
|
||||
} else if (searchWidget.options?.provider === "custom") {
|
||||
searchProvider = {
|
||||
url: searchWidget.options.url,
|
||||
};
|
||||
searchProvider = searchWidget.options;
|
||||
} else {
|
||||
searchProvider = searchProviders[searchWidget.options?.provider];
|
||||
}
|
||||
// to pass to quicklaunch
|
||||
searchProvider.showSearchSuggestions = searchWidget.options?.showSearchSuggestions;
|
||||
}
|
||||
const headerStyle = settings?.headerStyle || "underlined";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue