Improved readability of URL for search sharing

This commit is contained in:
squidfunk 2022-12-11 15:53:36 +01:00
parent db74632076
commit ee1496499a

View File

@ -86,8 +86,15 @@ export function watchSearchShare(
map(({ value }) => {
const url = getLocation()
url.hash = ""
url.searchParams.delete("h")
url.searchParams.set("q", value)
/* Compute readable query strings */
value = value
.replace(/\s+/g, "+") /* Collapse whitespace */
.replace(/&/g, "%26") /* Escape '&' character */
.replace(/=/g, "%3D") /* Escape '=' character */
/* Replace query string */
url.search = `q=${value}`
return { url }
})
)