Merge branch 'buscador' into 'master'

Codificar correctamente los parámetros de búsqueda

See merge request sutty/jekyll/sutty-base-jekyll-theme!15
This commit is contained in:
fauno 2021-09-17 18:50:01 +00:00
commit 93e35ebf66

View file

@ -16,10 +16,10 @@ export default class extends Controller {
}
connect () {
const q = window.location.search.match(/^\?q=(?<q>.*)&?/)
const q = new URLSearchParams(window.location.search).get('q').trim()
if (q) {
this.qTarget.value = decodeURI(q.groups.q)
this.qTarget.value = q
this.search()
}
}
@ -52,8 +52,9 @@ export default class extends Controller {
const template = await request.text()
const html = await this.engine.parseAndRender(template, { q, site, results })
const title = `${site.i18n.search.title} - ${q}`
const query = new URLSearchParams({ q })
window.history.pushState({ q }, title, `?q=${encodeURI(q)}`)
window.history.pushState({ q }, title, `?${query.toString()}`)
document.title = title
main.innerHTML = html