aboutsummaryrefslogtreecommitdiff
path: root/src/shared/urls.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-12-09 10:19:08 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-12-09 10:19:08 +0900
commit1f89464e4285936bdd509e2607aa70e93d5383a4 (patch)
treed431b1671f5d59a5869445bd165140203ad4c8e4 /src/shared/urls.js
parentb735317c60f24c9f60f007ac3503b37b7905e07b (diff)
Add gh/gH to open home page
Diffstat (limited to 'src/shared/urls.js')
-rw-r--r--src/shared/urls.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/shared/urls.js b/src/shared/urls.js
index d6c31e6..efdbcdb 100644
--- a/src/shared/urls.js
+++ b/src/shared/urls.js
@@ -5,7 +5,7 @@ const trimStart = (str) => {
const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:'];
-const normalizeUrl = (keywords, searchSettings) => {
+const searchUrl = (keywords, searchSettings) => {
try {
let u = new URL(keywords);
if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
@@ -28,4 +28,20 @@ const normalizeUrl = (keywords, searchSettings) => {
return template.replace('{}', encodeURIComponent(query));
};
-export { normalizeUrl };
+const normalizeUrl = (url) => {
+ try {
+ let u = new URL(url);
+ if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) {
+ return u.href;
+ }
+ } catch (e) {
+ // fallthrough
+ }
+ return 'http://' + url;
+};
+
+const homepageUrls = (value) => {
+ return value.split('|').map(normalizeUrl);
+};
+
+export { searchUrl, normalizeUrl, homepageUrls };