Commit fc11b11c authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add very preliminary search for Archéo Lex codes.

parent 751c2361
......@@ -19,6 +19,7 @@
export default {
data() {
return {
searchPath: "recherche",
term: "",
}
},
......@@ -27,9 +28,9 @@
event.preventDefault()
const limit = 10
const { term } = this.get()
const { searchPath, term } = this.get()
goto(buildSearchUrl("recherche", { limit, offset: 0, term }))
goto(buildSearchUrl(searchPath, { limit, offset: 0, term }))
},
},
}
......
......@@ -2,7 +2,7 @@
<title>{config.title}</title>
</svelte:head>
<SearchForm {term}/>
<SearchForm searchPath="recherche" {term}/>
<section class="mx-2">
<h1 class="my-4">Dossiers législatifs en cours</h1>
......
......@@ -2,7 +2,7 @@
<title>Recherche | {config.title}</title>
</svelte:head>
<SearchForm {term}/>
<SearchForm searchPath="recherche" {term}/>
{#if hits && hits.length > 0}
<ul class="list-reset">
......
<svelte:head>
<title>Recherche | {config.title}</title>
</svelte:head>
<SearchForm searchPath="recherche_codes" {term}/>
{#if hits && hits.length > 0}
<ul class="list-reset">
{#each hits as hit}
<li>
<a href="https://archeo-lex.fr/codes/{hit.filename.split(".")[0]}" target="_blank">{hit.filename}</a>
</li>
{/each}
</ul>
{/if}
<script>
import resolveUrl from "url-resolve"
import config from "../config"
import { buildSearchUrl } from "../strings"
export default {
components: {
SearchForm: "../components/SearchForm.html",
},
helpers: {
config,
},
async preload({ /* params, */ query }) {
const term = query.q || ""
const url = buildSearchUrl(resolveUrl(config.searchUrl, "codes"), {
term: term,
})
let response = await this.fetch(url, {
credentials: "same-origin",
})
let result =
response.ok
? await response.json()
: { error: { code: response.status, message: await response.text() } }
if (result.error) {
console.log(`An error occured while calling ${url}:`, result)
}
return {
...result,
term,
}
},
}
</script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment