mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-27 15:44:27 +02:00
✨ Adds web search functionality
This commit is contained in:
parent
5db0909e37
commit
411357c5b6
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<form>
|
<form @submit.prevent="searchSubmitted">
|
||||||
<label for="filter-tiles">{{ $t('search.search-label') }}</label>
|
<label for="filter-tiles">{{ $t('search.search-label') }}</label>
|
||||||
<input
|
<input
|
||||||
id="filter-tiles"
|
id="filter-tiles"
|
||||||
@ -16,12 +16,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import router from '@/router';
|
||||||
import ArrowKeyNavigation from '@/utils/ArrowKeyNavigation';
|
import ArrowKeyNavigation from '@/utils/ArrowKeyNavigation';
|
||||||
|
import ErrorHandler from '@/utils/ErrorHandler';
|
||||||
import { getCustomKeyShortcuts } from '@/utils/ConfigHelpers';
|
import { getCustomKeyShortcuts } from '@/utils/ConfigHelpers';
|
||||||
|
import { searchEngineUrls, defaultSearchEngine, defaultSearchOpeningMethod } from '@/utils/defaults';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'FilterTile',
|
name: 'FilterTile',
|
||||||
|
inject: ['config'],
|
||||||
props: {
|
props: {
|
||||||
active: Boolean,
|
active: Boolean,
|
||||||
},
|
},
|
||||||
@ -74,6 +77,40 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
launchWebSearch(url, method) {
|
||||||
|
switch (method) {
|
||||||
|
case 'newtab':
|
||||||
|
window.open(url, '_blank');
|
||||||
|
break;
|
||||||
|
case 'sametab':
|
||||||
|
window.open(url, '_self');
|
||||||
|
break;
|
||||||
|
case 'workspace':
|
||||||
|
router.push({ name: 'workspace', query: { url } });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ErrorHandler(`Unknown opening method: ${method}`);
|
||||||
|
window.open(url, '_blank');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
searchSubmitted() {
|
||||||
|
// Get search preferences from appConfig
|
||||||
|
const { appConfig } = this.config;
|
||||||
|
const searchPrefs = appConfig.webSearch || {};
|
||||||
|
if (!searchPrefs.disableWebSearch) { // Only proceed if user hasn't disabled web search
|
||||||
|
const openingMethod = searchPrefs.openingMethod || defaultSearchOpeningMethod;
|
||||||
|
// Get search engine, and make URL
|
||||||
|
const searchEngine = searchPrefs.searchEngine || defaultSearchEngine;
|
||||||
|
let searchUrl = searchEngineUrls[searchEngine];
|
||||||
|
if (!searchUrl) ErrorHandler(`Search engine not found - ${searchEngine}`);
|
||||||
|
if (searchEngine === 'custom' && searchPrefs.customSearchEngine) {
|
||||||
|
searchUrl = searchPrefs.customSearchEngine;
|
||||||
|
}
|
||||||
|
// Append users encoded query onto search URL, and launch
|
||||||
|
searchUrl += encodeURIComponent(this.input);
|
||||||
|
this.launchWebSearch(searchUrl, openingMethod);
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -152,6 +152,35 @@ module.exports = {
|
|||||||
localPath: '/item-icons',
|
localPath: '/item-icons',
|
||||||
faviconName: 'favicon.ico',
|
faviconName: 'favicon.ico',
|
||||||
},
|
},
|
||||||
|
/* URLs for web search engines */
|
||||||
|
searchEngineUrls: {
|
||||||
|
// Common
|
||||||
|
duckduckgo: 'https://duckduckgo.com/?q=',
|
||||||
|
google: 'https://google.com/search?q=',
|
||||||
|
whoogle: 'https://whoogle.sdf.org/search?q=',
|
||||||
|
qwant: 'https://www.qwant.com/?q=',
|
||||||
|
startpage: 'https://www.startpage.com/do/search?query=',
|
||||||
|
// Niche
|
||||||
|
'searx-bar': 'https://searx.bar/search?q=',
|
||||||
|
'searx-info': 'https://searx.info/search?q=',
|
||||||
|
'searx-tiekoetter': 'https://searx.tiekoetter.com/search?q=',
|
||||||
|
'searx-bissisoft': 'https://searx.bissisoft.com/search?q=',
|
||||||
|
ecosia: 'https://www.ecosia.org/search?q=',
|
||||||
|
metager: 'https://metager.org/meta/meta.ger3?eingabe=',
|
||||||
|
swisscows: 'https://swisscows.com/web?query=',
|
||||||
|
mojeek: 'https://www.mojeek.com/search?q=',
|
||||||
|
peekier: 'https://peekier.com/#!',
|
||||||
|
// Specific
|
||||||
|
wikipedia: 'https://en.wikipedia.org/w/?search=',
|
||||||
|
stackoverflow: 'https://stackoverflow.com/search?q=',
|
||||||
|
wolframalpha: 'https://www.wolframalpha.com/input/?i=',
|
||||||
|
reddit: 'https://www.reddit.com/search/?q=',
|
||||||
|
youtube: 'https://youtube.com/results?q=',
|
||||||
|
github: 'https://github.com/search?q=',
|
||||||
|
bbc: 'https://www.bbc.co.uk/search?q=',
|
||||||
|
},
|
||||||
|
defaultSearchEngine: 'duckduckgo',
|
||||||
|
defaultSearchOpeningMethod: 'newtab',
|
||||||
/* Available built-in colors for the theme builder */
|
/* Available built-in colors for the theme builder */
|
||||||
swatches: [
|
swatches: [
|
||||||
['#eb5cad', '#985ceb', '#5346f3', '#5c90eb'],
|
['#eb5cad', '#985ceb', '#5346f3', '#5c90eb'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user