chore: formatting

This commit is contained in:
Maciej Jur 2024-07-02 00:47:23 +02:00
parent 57e247b573
commit 9ef6fe4e3c
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
7 changed files with 127 additions and 127 deletions

View file

@ -1,21 +1,21 @@
{
"name": "search",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@tsconfig/svelte": "^5.0.4",
"svelte": "5.0.0-next.169",
"svelte-check": "^3.8.1",
"tslib": "^2.6.3",
"typescript": "^5.2.2",
"vite": "^5.3.1"
}
"name": "search",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@tsconfig/svelte": "^5.0.4",
"svelte": "5.0.0-next.169",
"svelte-check": "^3.8.1",
"tslib": "^2.6.3",
"typescript": "^5.2.2",
"vite": "^5.3.1"
}
}

120
js/search/src/App.svelte Executable file → Normal file
View file

@ -10,88 +10,88 @@ const require = (path: string) => import(/* @vite-ignore */path);
function sync(): void {
query = new URLSearchParams(window.location.search).get('q') || '';
query = new URLSearchParams(window.location.search).get('q') || '';
}
function onInput(): ChangeEventHandler<HTMLInputElement> {
let debounce: number | undefined;
let debounce: number | undefined;
return event => {
clearTimeout(debounce);
const value = event.currentTarget.value;
const url = new URL(window.location.href);
(value)
? url.searchParams.set('q', value)
: url.searchParams.delete('q');
debounce = setTimeout(() => window.history.pushState({}, '', url), 1000);
}
return event => {
clearTimeout(debounce);
const value = event.currentTarget.value;
const url = new URL(window.location.href);
(value)
? url.searchParams.set('q', value)
: url.searchParams.delete('q');
debounce = setTimeout(() => window.history.pushState({}, '', url), 1000);
}
}
function onScroll(): UIEventHandler<Window> {
let throttle = Date.now();
let throttle = Date.now();
return event => {
const now = Date.now();
if (throttle + 200 > now) return;
return event => {
const now = Date.now();
if (throttle + 200 > now) return;
const { scrollHeight } = document.documentElement;
const { innerHeight, scrollY } = event.currentTarget;
const { scrollHeight } = document.documentElement;
const { innerHeight, scrollY } = event.currentTarget;
const distance = scrollHeight - (innerHeight + scrollY);
if (distance < 100) {
limit += 5;
throttle = now;
}
}
const distance = scrollHeight - (innerHeight + scrollY);
if (distance < 100) {
limit += 5;
throttle = now;
}
}
}
$effect(() => {
sync();
require('/pagefind/pagefind.js').then(pf => client = pf);
sync();
require('/pagefind/pagefind.js').then(pf => client = pf);
});
</script>
<svelte:window
on:popstate={sync}
on:scroll={onScroll()}/>
on:popstate={sync}
on:scroll={onScroll()}/>
{#snippet tile(data: PagefindDocument)}
<a class="c-search__result" href={data.url}>
<header class="c-search__header">
<h2 class="c-search__title">
{data.meta.title}
</h2>
</header>
<div class="c-search__excerpt">
{@html data.excerpt}
</div>
</a>
<a class="c-search__result" href={data.url}>
<header class="c-search__header">
<h2 class="c-search__title">
{data.meta.title}
</h2>
</header>
<div class="c-search__excerpt">
{@html data.excerpt}
</div>
</a>
{/snippet}
<article class="c-search">
<h1>Search</h1>
<input class="c-search__input" placeholder="Start typing here!"
bind:value={query}
on:input={onInput()}
on:input={() => limit = 10}/>
<h1>Search</h1>
<input class="c-search__input" placeholder="Start typing here!"
bind:value={query}
on:input={onInput()}
on:input={() => limit = 10}/>
{#if query && result}
{#await result}
Loading...
{:then {results}}
<section class="c-search__results">
<div>Showing results for "{query}" ({results.length})</div>
{#each results.slice(0, limit) as page (page.id)}
{#await page.data()}
Loading...
{:then page}
{@render tile(page)}
{/await}
{/each}
</section>
{/await}
{:else}
<div>No results to show yet...</div>
{/if}
{#if query && result}
{#await result}
Loading...
{:then {results}}
<section class="c-search__results">
<div>Showing results for "{query}" ({results.length})</div>
{#each results.slice(0, limit) as page (page.id)}
{#await page.data()}
Loading...
{:then page}
{@render tile(page)}
{/await}
{/each}
</section>
{/await}
{:else}
<div>No results to show yet...</div>
{/if}
</article>

30
js/search/src/pagefind.d.ts vendored Executable file → Normal file
View file

@ -1,26 +1,26 @@
interface Pagefind {
search: (query: string) => Promise<PagefindResponse>;
search: (query: string) => Promise<PagefindResponse>;
}
interface PagefindResult {
id: string;
data: () => Promise<PagefindDocument>;
id: string;
data: () => Promise<PagefindDocument>;
}
interface PagefindResponse {
results: PagefindResult[];
results: PagefindResult[];
}
interface PagefindDocument {
url: string;
excerpt: string;
filters: {
author: string;
};
meta: {
title: string;
image: string;
};
content: string;
word_count: number;
url: string;
excerpt: string;
filters: {
author: string;
};
meta: {
title: string;
image: string;
};
content: string;
word_count: number;
}

View file

@ -1,7 +1,7 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
export default {
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
// for more information about preprocessors
preprocess: vitePreprocess(),
}

View file

@ -1,21 +1,21 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"resolveJsonModule": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
* Note that setting allowJs false does not prevent the use
* of JS in `.svelte` files.
*/
"allowJs": true,
"checkJs": true,
"isolatedModules": true,
"moduleDetection": "force"
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"resolveJsonModule": true,
/**
* Typecheck JS in `.svelte` and `.js` files by default.
* Disable checkJs if you'd like to use dynamic types in JS.
* Note that setting allowJs false does not prevent the use
* of JS in `.svelte` files.
*/
"allowJs": true,
"checkJs": true,
"isolatedModules": true,
"moduleDetection": "force"
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View file

@ -1,12 +1,12 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true
},
"include": ["vite.config.ts"]
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true
},
"include": ["vite.config.ts"]
}

View file

@ -372,7 +372,7 @@ fn build() {
.arg("--format=esm")
.arg("--bundle")
.arg("--splitting")
//.arg("--minify")
.arg("--minify")
.arg("--outdir=dist/js/")
.output()
.unwrap();