mirror of
https://github.com/xvvvyz/tilde.git
synced 2026-03-11 14:44:24 +00:00
allow full url search templates
This commit is contained in:
parent
d45c5d1468
commit
50160383fb
1 changed files with 11 additions and 11 deletions
22
index.html
22
index.html
|
|
@ -381,12 +381,12 @@
|
|||
});
|
||||
}
|
||||
|
||||
static #formatSearchUrl(url, searchPath, search) {
|
||||
if (!searchPath) return url;
|
||||
const [baseUrl] = Search.#splitUrl(url);
|
||||
const urlQuery = encodeURIComponent(search);
|
||||
searchPath = searchPath.replace(/{}/g, urlQuery);
|
||||
return baseUrl + searchPath;
|
||||
static #formatSearchUrl(commandUrl, searchTemplate, query) {
|
||||
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));
|
||||
}
|
||||
|
||||
static #hasProtocol(s) {
|
||||
|
|
@ -436,11 +436,11 @@
|
|||
};
|
||||
|
||||
static #splitUrl(url) {
|
||||
const parser = document.createElement('a');
|
||||
parser.href = url;
|
||||
const baseUrl = `${parser.protocol}//${parser.hostname}`;
|
||||
const rest = `${parser.pathname}${parser.search}`;
|
||||
return [baseUrl, rest];
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
const baseUrl = a.hostname ? `${a.protocol}//${a.hostname}` : null;
|
||||
const rest = `${a.pathname}${a.search}`;
|
||||
return [baseUrl, decodeURIComponent(rest)];
|
||||
}
|
||||
|
||||
#close() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue