mirror of
https://github.com/xvvvyz/tilde.git
synced 2026-03-11 14:44:24 +00:00
remove unnecessary splitUrl helper function
This commit is contained in:
parent
609760aa60
commit
11e16b371c
1 changed files with 5 additions and 18 deletions
23
index.html
23
index.html
|
|
@ -333,10 +333,9 @@
|
|||
|
||||
static #formatSearchUrl(searchTemplate, query, commandUrl) {
|
||||
if (!searchTemplate) return commandUrl;
|
||||
const [commandBase] = Search.#splitUrl(commandUrl);
|
||||
const [searchBase, path] = Search.#splitUrl(searchTemplate);
|
||||
const base = searchBase ?? commandBase;
|
||||
return `${base}${path}`.replace(/{}/g, encodeURIComponent(query));
|
||||
const { origin: commandOrigin } = new URL(searchTemplate, commandUrl);
|
||||
const { href } = new URL(searchTemplate, commandOrigin);
|
||||
return href.replace(/{}/g, encodeURIComponent(query));
|
||||
}
|
||||
|
||||
static #hasProtocol(s) {
|
||||
|
|
@ -375,26 +374,14 @@
|
|||
|
||||
if (COMMANDS.has(pathKey)) {
|
||||
const { url: base } = COMMANDS.get(pathKey);
|
||||
const [baseUrl] = Search.#splitUrl(base);
|
||||
const url = `${baseUrl}/${path}`;
|
||||
return { key: pathKey, path, query, splitBy, url };
|
||||
const { origin } = new URL(base);
|
||||
return { key: pathKey, path, query, splitBy, url: `${origin}/${path}` };
|
||||
}
|
||||
|
||||
const url = Search.#formatSearchUrl(CONFIG.defaultSearchTemplate, query);
|
||||
return { query, search: query, url };
|
||||
};
|
||||
|
||||
static #splitUrl(url) {
|
||||
try {
|
||||
const u = new URL(url);
|
||||
const base = `${u.protocol}//${u.hostname}`;
|
||||
const rest = decodeURIComponent(`${u.pathname}${u.search}${u.hash}`);
|
||||
return [base, rest];
|
||||
} catch (e) {
|
||||
return [null, url];
|
||||
}
|
||||
}
|
||||
|
||||
#close() {
|
||||
this.#input.value = '';
|
||||
this.#input.blur();
|
||||
|
|
|
|||
Loading…
Reference in a new issue