-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add simple search and display basic metadata for the …
…inscriptions
- Loading branch information
Showing
1 changed file
with
93 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,101 @@ | ||
<script> | ||
import { page } from '$app/stores'; | ||
import BaseLink from '$lib/components/BaseLink.svelte'; | ||
import * as config from '$lib/config'; | ||
import { onMount } from 'svelte'; | ||
/** @type {import('./$types').PageData} */ | ||
export let data; | ||
let inscriptions = data.corpus; | ||
let finishedSearch = false; | ||
let keywords = ''; | ||
function handleReset() { | ||
inscriptions = data.corpus; | ||
finishedSearch = false; | ||
keywords = ''; | ||
} | ||
function handleSearch() { | ||
finishedSearch = true; | ||
if (!keywords) { | ||
inscriptions = data.corpus; | ||
return; | ||
} | ||
inscriptions = data.corpus.filter((inscription) => { | ||
return ( | ||
!keywords || | ||
keywords | ||
.split(' ') | ||
.map((keyword) => keyword.toLowerCase()) | ||
.every((keyword) => { | ||
return ( | ||
inscription.metadata.keywords.some((mk) => mk.includes(keyword)) || | ||
inscription.metadata.title.toLowerCase().includes(keyword) | ||
); | ||
}) | ||
); | ||
}); | ||
} | ||
onMount(() => { | ||
keywords = $page.url.searchParams.get('keywords') || ''; | ||
}); | ||
</script> | ||
|
||
<hgroup> | ||
<h1>{data.corpus.length.toLocaleString()} Inscriptions over x years across x locations</h1> | ||
<p>{config.description}</p> | ||
</hgroup> | ||
|
||
<section> | ||
<h2>Inscriptions</h2> | ||
<ol> | ||
{#each data.corpus as inscription} | ||
<li> | ||
<BaseLink href="inscription/{inscription.file}">{inscription.metadata.title}</BaseLink> | ||
</li> | ||
{/each} | ||
</ol> | ||
</section> | ||
<article> | ||
<hgroup> | ||
<h1>{data.corpus.length.toLocaleString()} Inscriptions over x years across x locations</h1> | ||
<p>{config.description}</p> | ||
</hgroup> | ||
|
||
<section> | ||
<form on:submit={() => handleSearch()} on:reset={() => handleReset()}> | ||
<label for="keywords">Keywords</label> | ||
<input type="text" name="keywords" id="keywords" bind:value={keywords} /> | ||
<input type="submit" value="Search" disabled={!keywords} /> | ||
<input type="reset" value="Reset" disabled={!keywords} /> | ||
</form> | ||
</section> | ||
|
||
<section> | ||
<hgroup> | ||
<h2>Inscriptions</h2> | ||
{#if finishedSearch} | ||
<h3> | ||
Displaying <em>{inscriptions.length}</em> inscriptions matching | ||
<em>{keywords.split(' ').join(', ')}</em> | ||
</h3> | ||
{/if} | ||
</hgroup> | ||
<ol> | ||
{#each inscriptions as inscription} | ||
<li> | ||
<h4> | ||
<BaseLink href="inscription/{inscription.file}">{inscription.metadata.title}</BaseLink> | ||
</h4> | ||
<dl> | ||
<dt>Settlement</dt> | ||
<dd>{inscription.metadata.settlement}</dd> | ||
<dt>Repository</dt> | ||
<dd>{inscription.metadata.repository?._ || 'N/A'}</dd> | ||
<dt>Language</dt> | ||
<dd>{inscription.metadata.textLang?._ || 'N/A'}</dd> | ||
</dl> | ||
</li> | ||
{/each} | ||
</ol> | ||
</section> | ||
</article> | ||
|
||
<style> | ||
dt { | ||
margin-block-start: unset; | ||
} | ||
</style> |