mwmbl/front-end/src/utils/suggestions.js
2023-10-12 17:17:42 +01:00

24 lines
608 B
JavaScript

/**
* Handle redirect requests from the suggestion back-end.
*/
import config from "../../config.js";
const redirectToSuggestions = () => {
const search = decodeURIComponent(document.location.search).replace(/\+/g, ' ').substr(3);
console.log("Search", search);
for (const [command, urlTemplate] of Object.entries(config.commands)) {
console.log("Command", command);
if (search.startsWith(command)) {
const newUrl = urlTemplate + search.substr(command.length);
window.location.replace(newUrl);
return true;
}
}
return false;
}
export {
redirectToSuggestions
};