mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-21 04:19:37 +02:00
Added redirect function to search bar
This commit is contained in:
parent
a162450568
commit
da928f20a2
6 changed files with 35 additions and 15 deletions
|
@ -6,6 +6,7 @@ import { searchConfig } from '.';
|
|||
export const searchParser = (searchQuery: string): SearchResult => {
|
||||
const result: SearchResult = {
|
||||
isLocal: false,
|
||||
isURL: false,
|
||||
sameTab: false,
|
||||
search: '',
|
||||
query: {
|
||||
|
@ -15,6 +16,13 @@ export const searchParser = (searchQuery: string): SearchResult => {
|
|||
},
|
||||
};
|
||||
|
||||
// Check if url or ip was passed
|
||||
const urlRegex =
|
||||
/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|^((http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
|
||||
|
||||
result.isURL = urlRegex.test(searchQuery);
|
||||
|
||||
// Match prefix and query
|
||||
const splitQuery = searchQuery.match(/^\/([a-z]+)[ ](.+)$/i);
|
||||
|
||||
const prefix = splitQuery
|
||||
|
@ -27,6 +35,7 @@ export const searchParser = (searchQuery: string): SearchResult => {
|
|||
|
||||
const query = queries.find((q: Query) => q.prefix === prefix);
|
||||
|
||||
// If search provider was found
|
||||
if (query) {
|
||||
result.query = query;
|
||||
result.search = search;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue