From 50160383fbbf265d2d637a2f1fc4e75961cf4794 Mon Sep 17 00:00:00 2001 From: cade Date: Thu, 13 Jun 2024 16:37:01 -0700 Subject: [PATCH] allow full url search templates --- index.html | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index d11a4a1..06a65c1 100644 --- a/index.html +++ b/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() {