mirror of
https://github.com/jorgev259/soc_site-astro.git
synced 2025-06-29 07:57:41 +00:00
More strict search query parsing
This commit is contained in:
parent
d4423f465d
commit
87b2fc0796
2 changed files with 7 additions and 3 deletions
|
|
@ -44,8 +44,12 @@ const placeholder = getRandom(placeholders)
|
|||
searchForm?.addEventListener('submit', (ev: Event) => {
|
||||
ev.preventDefault()
|
||||
const formData = new FormData(searchForm)
|
||||
const query = (formData.get('query') as string).trim()
|
||||
|
||||
if (!query || query.length < 1) return
|
||||
|
||||
const url = new URL('/search', window.location.origin)
|
||||
url.searchParams.append('q', formData.get('query') as string)
|
||||
url.searchParams.append('q', query)
|
||||
|
||||
window.location.href = url.toString()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ import * as m from 'paraglide/messages'
|
|||
import AlbumSearch from 'components/search/AlbumSearch.astro'
|
||||
import BaseLayout from 'layouts/base.astro'
|
||||
|
||||
const query = Astro.url.searchParams.get('q')
|
||||
const query = (Astro.url.searchParams.get('q') ?? '').trim()
|
||||
const page = Astro.url.searchParams.get('page') || '1'
|
||||
|
||||
if (!query) return Astro.redirect(404)
|
||||
if (!query || query.length < 1) return Astro.redirect(404)
|
||||
---
|
||||
|
||||
<BaseLayout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue