chore: formatting
This commit is contained in:
parent
57e247b573
commit
9ef6fe4e3c
|
@ -1,21 +1,21 @@
|
||||||
{
|
{
|
||||||
"name": "search",
|
"name": "search",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
|
"check": "svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/vite-plugin-svelte": "^3.1.1",
|
"@sveltejs/vite-plugin-svelte": "^3.1.1",
|
||||||
"@tsconfig/svelte": "^5.0.4",
|
"@tsconfig/svelte": "^5.0.4",
|
||||||
"svelte": "5.0.0-next.169",
|
"svelte": "5.0.0-next.169",
|
||||||
"svelte-check": "^3.8.1",
|
"svelte-check": "^3.8.1",
|
||||||
"tslib": "^2.6.3",
|
"tslib": "^2.6.3",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "^5.2.2",
|
||||||
"vite": "^5.3.1"
|
"vite": "^5.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
120
js/search/src/App.svelte
Executable file → Normal file
120
js/search/src/App.svelte
Executable file → Normal file
|
@ -10,88 +10,88 @@ const require = (path: string) => import(/* @vite-ignore */path);
|
||||||
|
|
||||||
|
|
||||||
function sync(): void {
|
function sync(): void {
|
||||||
query = new URLSearchParams(window.location.search).get('q') || '';
|
query = new URLSearchParams(window.location.search).get('q') || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function onInput(): ChangeEventHandler<HTMLInputElement> {
|
function onInput(): ChangeEventHandler<HTMLInputElement> {
|
||||||
let debounce: number | undefined;
|
let debounce: number | undefined;
|
||||||
|
|
||||||
return event => {
|
return event => {
|
||||||
clearTimeout(debounce);
|
clearTimeout(debounce);
|
||||||
const value = event.currentTarget.value;
|
const value = event.currentTarget.value;
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
(value)
|
(value)
|
||||||
? url.searchParams.set('q', value)
|
? url.searchParams.set('q', value)
|
||||||
: url.searchParams.delete('q');
|
: url.searchParams.delete('q');
|
||||||
debounce = setTimeout(() => window.history.pushState({}, '', url), 1000);
|
debounce = setTimeout(() => window.history.pushState({}, '', url), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onScroll(): UIEventHandler<Window> {
|
function onScroll(): UIEventHandler<Window> {
|
||||||
let throttle = Date.now();
|
let throttle = Date.now();
|
||||||
|
|
||||||
return event => {
|
return event => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (throttle + 200 > now) return;
|
if (throttle + 200 > now) return;
|
||||||
|
|
||||||
const { scrollHeight } = document.documentElement;
|
const { scrollHeight } = document.documentElement;
|
||||||
const { innerHeight, scrollY } = event.currentTarget;
|
const { innerHeight, scrollY } = event.currentTarget;
|
||||||
|
|
||||||
const distance = scrollHeight - (innerHeight + scrollY);
|
const distance = scrollHeight - (innerHeight + scrollY);
|
||||||
if (distance < 100) {
|
if (distance < 100) {
|
||||||
limit += 5;
|
limit += 5;
|
||||||
throttle = now;
|
throttle = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
sync();
|
sync();
|
||||||
require('/pagefind/pagefind.js').then(pf => client = pf);
|
require('/pagefind/pagefind.js').then(pf => client = pf);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<svelte:window
|
<svelte:window
|
||||||
on:popstate={sync}
|
on:popstate={sync}
|
||||||
on:scroll={onScroll()}/>
|
on:scroll={onScroll()}/>
|
||||||
|
|
||||||
{#snippet tile(data: PagefindDocument)}
|
{#snippet tile(data: PagefindDocument)}
|
||||||
<a class="c-search__result" href={data.url}>
|
<a class="c-search__result" href={data.url}>
|
||||||
<header class="c-search__header">
|
<header class="c-search__header">
|
||||||
<h2 class="c-search__title">
|
<h2 class="c-search__title">
|
||||||
{data.meta.title}
|
{data.meta.title}
|
||||||
</h2>
|
</h2>
|
||||||
</header>
|
</header>
|
||||||
<div class="c-search__excerpt">
|
<div class="c-search__excerpt">
|
||||||
{@html data.excerpt}
|
{@html data.excerpt}
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|
||||||
<article class="c-search">
|
<article class="c-search">
|
||||||
<h1>Search</h1>
|
<h1>Search</h1>
|
||||||
<input class="c-search__input" placeholder="Start typing here!"
|
<input class="c-search__input" placeholder="Start typing here!"
|
||||||
bind:value={query}
|
bind:value={query}
|
||||||
on:input={onInput()}
|
on:input={onInput()}
|
||||||
on:input={() => limit = 10}/>
|
on:input={() => limit = 10}/>
|
||||||
|
|
||||||
{#if query && result}
|
{#if query && result}
|
||||||
{#await result}
|
{#await result}
|
||||||
Loading...
|
Loading...
|
||||||
{:then {results}}
|
{:then {results}}
|
||||||
<section class="c-search__results">
|
<section class="c-search__results">
|
||||||
<div>Showing results for "{query}" ({results.length})</div>
|
<div>Showing results for "{query}" ({results.length})</div>
|
||||||
{#each results.slice(0, limit) as page (page.id)}
|
{#each results.slice(0, limit) as page (page.id)}
|
||||||
{#await page.data()}
|
{#await page.data()}
|
||||||
Loading...
|
Loading...
|
||||||
{:then page}
|
{:then page}
|
||||||
{@render tile(page)}
|
{@render tile(page)}
|
||||||
{/await}
|
{/await}
|
||||||
{/each}
|
{/each}
|
||||||
</section>
|
</section>
|
||||||
{/await}
|
{/await}
|
||||||
{:else}
|
{:else}
|
||||||
<div>No results to show yet...</div>
|
<div>No results to show yet...</div>
|
||||||
{/if}
|
{/if}
|
||||||
</article>
|
</article>
|
||||||
|
|
30
js/search/src/pagefind.d.ts
vendored
Executable file → Normal file
30
js/search/src/pagefind.d.ts
vendored
Executable file → Normal file
|
@ -1,26 +1,26 @@
|
||||||
interface Pagefind {
|
interface Pagefind {
|
||||||
search: (query: string) => Promise<PagefindResponse>;
|
search: (query: string) => Promise<PagefindResponse>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PagefindResult {
|
interface PagefindResult {
|
||||||
id: string;
|
id: string;
|
||||||
data: () => Promise<PagefindDocument>;
|
data: () => Promise<PagefindDocument>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PagefindResponse {
|
interface PagefindResponse {
|
||||||
results: PagefindResult[];
|
results: PagefindResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PagefindDocument {
|
interface PagefindDocument {
|
||||||
url: string;
|
url: string;
|
||||||
excerpt: string;
|
excerpt: string;
|
||||||
filters: {
|
filters: {
|
||||||
author: string;
|
author: string;
|
||||||
};
|
};
|
||||||
meta: {
|
meta: {
|
||||||
title: string;
|
title: string;
|
||||||
image: string;
|
image: string;
|
||||||
};
|
};
|
||||||
content: string;
|
content: string;
|
||||||
word_count: number;
|
word_count: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
|
||||||
// for more information about preprocessors
|
// for more information about preprocessors
|
||||||
preprocess: vitePreprocess(),
|
preprocess: vitePreprocess(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
{
|
{
|
||||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
/**
|
/**
|
||||||
* Typecheck JS in `.svelte` and `.js` files by default.
|
* Typecheck JS in `.svelte` and `.js` files by default.
|
||||||
* Disable checkJs if you'd like to use dynamic types in JS.
|
* Disable checkJs if you'd like to use dynamic types in JS.
|
||||||
* Note that setting allowJs false does not prevent the use
|
* Note that setting allowJs false does not prevent the use
|
||||||
* of JS in `.svelte` files.
|
* of JS in `.svelte` files.
|
||||||
*/
|
*/
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
"isolatedModules": true,
|
"isolatedModules": true,
|
||||||
"moduleDetection": "force"
|
"moduleDetection": "force"
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
|
||||||
"references": [{ "path": "./tsconfig.node.json" }]
|
"references": [{ "path": "./tsconfig.node.json" }]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noEmit": true
|
"noEmit": true
|
||||||
},
|
},
|
||||||
"include": ["vite.config.ts"]
|
"include": ["vite.config.ts"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,7 +372,7 @@ fn build() {
|
||||||
.arg("--format=esm")
|
.arg("--format=esm")
|
||||||
.arg("--bundle")
|
.arg("--bundle")
|
||||||
.arg("--splitting")
|
.arg("--splitting")
|
||||||
//.arg("--minify")
|
.arg("--minify")
|
||||||
.arg("--outdir=dist/js/")
|
.arg("--outdir=dist/js/")
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in a new issue