light-mode fixes, prevent empty search queries from getting sent

This commit is contained in:
Silas 2024-06-12 09:39:09 -04:00
parent 31219f6d06
commit e54a60359c
Failed to generate hash of commit
4 changed files with 13 additions and 9 deletions

View File

@ -9,7 +9,10 @@
const { value } = target as HTMLInputElement; const { value } = target as HTMLInputElement;
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(async () => { timer = setTimeout(async () => {
// const section = window.location.pathname.split('/')[1]; if (!value) {
searchResults.set([]);
return;
}
const response = await fetch(`/api/search?q=${encodeURIComponent(value)}`); const response = await fetch(`/api/search?q=${encodeURIComponent(value)}`);
if (response.ok) { if (response.ok) {
const data: SearchResult[] = await response.json(); const data: SearchResult[] = await response.json();

View File

@ -2,6 +2,7 @@
import { T } from '@threlte/core'; import { T } from '@threlte/core';
export let size = 100; export let size = 100;
export let count = 500; export let count = 500;
export let color = localStorage.getItem('theme') === 'forest' ? 'white' : '#a991f7';
const positions = new Float32Array(count * 3); const positions = new Float32Array(count * 3);
@ -26,5 +27,5 @@
}} }}
/> />
</T.BufferGeometry> </T.BufferGeometry>
<T.PointsMaterial size={0.1} /> <T.PointsMaterial size={0.1} {color} />
</T.Points> </T.Points>

View File

@ -79,10 +79,10 @@
<div transition:fade={{ duration: 1200 }}> <div transition:fade={{ duration: 1200 }}>
<span class="font-bold text-primary">{currentGreeting.greeting}</span> <span class="font-bold text-primary">{currentGreeting.greeting}</span>
{#if currentGreeting.romanisation} {#if currentGreeting.romanisation}
<span class="text-gray-500">( {currentGreeting.romanisation} )</span> <span>( {currentGreeting.romanisation} )</span>
{/if} {/if}
</div> </div>
<p class="text-gray-300" transition:fade={{ delay: 400, duration: 400 }}> <p transition:fade={{ delay: 400, duration: 400 }}>
That's {currentGreeting.language} for hello! That's {currentGreeting.language} for hello!
</p> </p>
{/if} {/if}

View File

@ -1,7 +1,7 @@
// eslint-disable-next-line // eslint-disable-next-line
import * as tf from '@tensorflow/tfjs-node'; import * as tf from '@tensorflow/tfjs-node';
import postEmbeddings from '$lib/utils/poetry/embeddings.json'; import postEmbeddings from '$lib/utils/poetry/embeddings.json';
import { json } from '@sveltejs/kit'; import { error, json } from '@sveltejs/kit';
import { getModel, type Embedding, type SearchResult } from '$lib/utils/search'; import { getModel, type Embedding, type SearchResult } from '$lib/utils/search';
import { fetchMarkdownPosts } from '$lib/utils'; import { fetchMarkdownPosts } from '$lib/utils';
import Fuse from 'fuse.js'; import Fuse from 'fuse.js';
@ -9,8 +9,8 @@ import Fuse from 'fuse.js';
// Search handler // Search handler
export const GET = async ({ url }: { url: URL }) => { export const GET = async ({ url }: { url: URL }) => {
const searchQuery = url.searchParams.get('q'); const searchQuery = url.searchParams.get('q');
if (!searchQuery) { if (!searchQuery || searchQuery === ' ') {
return { status: 400, body: { error: 'Query parameter "q" is required' } }; return error(400, 'Empty query');
} }
try { try {
@ -75,8 +75,8 @@ export const GET = async ({ url }: { url: URL }) => {
.slice(0, 10); .slice(0, 10);
return json(semanticResults); return json(semanticResults);
} catch (error) { } catch (err) {
return { status: 500, body: { error: (error as Error).message } }; return error(500, (err as Error).message);
} }
}; };