web search done right
make explore work without javascript and add browser features section to privacy statement
Mikkel Denkerc8447c9ef02d
diff --git a/frontend/src/lib/components/Button.svelte b/frontend/src/lib/components/Button.svelteindex cc9266f3..7609ce08 100644--- a/frontend/src/lib/components/Button.svelte+++ b/frontend/src/lib/components/Button.svelte@@ -1,5 +1,4 @@<script lang="ts">- import { twMerge } from 'tailwind-merge';import { getButtonTailwindStyle, type ButtonKind } from '$lib/themes';export let title: string | undefined = void 0;diff --git a/frontend/src/lib/components/Site.svelte b/frontend/src/lib/components/Site.svelteindex f0e4349d..c4ce05fa 100644--- a/frontend/src/lib/components/Site.svelte+++ b/frontend/src/lib/components/Site.svelte@@ -7,25 +7,27 @@const dispatch = createEventDispatcher<{ delete: null }>();</script>-<span class="group flex overflow-hidden rounded-lg bg-secondary transition">+<span class="bg-secondary group flex overflow-hidden rounded-lg transition"><a{href}target="_blank"class={twMerge('bg-secondary py-2','text-primary-content',- 'transition hover:bg-secondary-focus',+ 'hover:bg-secondary-focus transition','pl-3 pr-2',)}><slot /></a>- <span class="my-2 w-px bg-primary-content transition group-hover:bg-transparent" />+ <span+ class="noscript:hidden bg-primary-content my-2 w-px transition group-hover:bg-transparent"+ /><buttonclass={twMerge(- 'cursor-pointer bg-secondary px-2 text-sm',+ 'bg-secondary cursor-pointer px-2 text-sm','text-primary-content',- 'transition hover:bg-secondary-focus',+ 'hover:bg-secondary-focus noscript:hidden transition',)}on:click={() => dispatch('delete')}>diff --git a/frontend/src/routes/explore/+page.svelte b/frontend/src/routes/explore/+page.svelteindex d83b5140..fb511543 100644--- a/frontend/src/routes/explore/+page.svelte+++ b/frontend/src/routes/explore/+page.svelte@@ -2,7 +2,7 @@import XMark from '~icons/heroicons/x-mark';import PlusCircleOutline from '~icons/heroicons/plus-circle';import ChevronDown from '~icons/heroicons/chevron-down';- import { api, type ScoredHost } from '$lib/api';+ import { api } from '$lib/api';import Button from '$lib/components/Button.svelte';import Site from '$lib/components/Site.svelte';import Select from '$lib/components/Select.svelte';@@ -11,15 +11,22 @@import { twJoin } from 'tailwind-merge';import { match } from 'ts-pattern';import Callout from '$lib/components/Callout.svelte';+ import type { PageData } from './$types';+ import { LIMIT_OPTIONS } from './conf';+ import { page } from '$app/stores';+ import { goto } from '$app/navigation';+ import { browser } from '$app/environment';- const LIMIT_OPTIONS = [10, 25, 50, 125, 250, 500, 1000];+ export let data: PageData;let inputWebsite = '';- let limit = LIMIT_OPTIONS[0];- let chosenHosts: string[] = [];- let similarHosts: ScoredHost[] = [];- let errorMessage = false;+ let limit = data.limit;+ let chosenHosts = data.chosenHosts;+ let similarHosts = data.similarHosts;+ let errorMessage = data.errorMessage;++ $: chosenHostString = chosenHosts.join(',');$: {api@@ -27,11 +34,37 @@.data.then((res) => (similarHosts = res));}+ $: {+ limit;+ updateBrowserState();+ }++ const updateBrowserState = () => {+ if (!browser) {+ return;+ }+ $page.url.searchParams.set('chosenHosts', chosenHosts.join(','));+ $page.url.searchParams.set('limit', limit.toString());+ goto($page.url, { replaceState: true });+ };++ $: {+ if (browser) {+ chosenHosts =+ $page.url.searchParams+ .get('chosenHosts')+ ?.split(',')+ .filter((host) => host.length > 0) ?? [];+ }+ }+const removeWebsite = async (host: string) => {if (chosenHosts.includes(host)) {chosenHosts = chosenHosts.filter((s) => s != host);+ updateBrowserState();}};+const addWebsite = async (host: string, clear = false) => {errorMessage = false;host = host.trim();@@ -45,6 +78,7 @@.with({ type: 'known' }, async ({ host }) => {if (clear) inputWebsite = '';if (!chosenHosts.includes(host)) chosenHosts = [...chosenHosts, host];+ updateBrowserState();}).exhaustive();};@@ -71,7 +105,7 @@</div><formclass={twJoin(- 'mb-2 flex w-full max-w-lg rounded-full border border-base-400 bg-base-100 p-[1px] pl-3 transition focus-within:shadow',+ 'border-base-400 bg-base-100 mb-2 flex w-full max-w-lg rounded-full border p-[1px] pl-3 transition focus-within:shadow',)}id="site-input-container"on:submit|preventDefault={() => addWebsite(inputWebsite, true)}@@ -86,8 +120,16 @@placeholder="www.example.com"bind:value={inputWebsite}/>+ <input class="hidden" type="text" name="chosenHosts" bind:value={chosenHostString} /><Button>Add</Button></form>+ <noscript>+ <div class="mb-2">+ <form>+ <Button pale kind="info">Clear All Sites</Button>+ </form>+ </div>+ </noscript>{#if errorMessage}<div class="my-2" transition:slide><Callout kind="warning" title="Unable to add page">@@ -102,10 +144,7 @@<div class="flex flex-wrap justify-center gap-x-5 gap-y-3" id="sites-list">{#each chosenHosts as site (site)}<div transition:slide={{ duration: 100 }} animate:flip={{ duration: 200 }}>- <Site- href="http://{site}"- on:delete={() => (chosenHosts = chosenHosts.filter((s) => s != site))}- >+ <Site href="http://{site}" on:delete={() => removeWebsite(site)}>{site}</Site></div>@@ -120,13 +159,15 @@<div class="flex space-x-1"><Selectid="limit"+ name="limit"+ form="site-input-container"class="cursor-pointer rounded border-none dark:bg-transparent"bind:value={limit}options={LIMIT_OPTIONS.map((value) => ({ value, label: value.toString() }))}/></div><div />- <Button on:click={exportAsOptic}>Export as optic</Button>+ <Button _class="noscript:hidden" on:click={exportAsOptic}>Export as optic</Button></div><div class="grid items-center gap-y-2">{#each similarHosts as host (host.host)}@@ -137,7 +178,7 @@><div><button- class={twJoin('group')}+ class={twJoin('noscript:hidden group')}on:click={() =>chosenHosts.includes(host.host)? removeWebsite(host.host)@@ -145,8 +186,7 @@><PlusCircleOutlineclass={twJoin(- 'text-xl transition group-hover:scale-105 group-active:scale-95',- chosenHosts.includes(host.host) ? 'rotate-45 text-error' : 'text-success',+ 'text-success text-xl group-hover:scale-105 group-active:scale-95',)}/></button>@@ -158,9 +198,9 @@</div>{/each}</div>- <div class="flex w-full justify-center">+ <div class="noscript:hidden flex w-full justify-center"><button- class="h-6 w-6 cursor-pointer rounded-full text-accent"+ class="text-accent h-6 w-6 cursor-pointer rounded-full"aria-label="Show more similar sites"on:click={() => {if (limit == LIMIT_OPTIONS[LIMIT_OPTIONS.length - 1]) {diff --git a/frontend/src/routes/explore/+page.ts b/frontend/src/routes/explore/+page.tsindex 4e0e105e..dd9c472d 100644--- a/frontend/src/routes/explore/+page.ts+++ b/frontend/src/routes/explore/+page.ts@@ -1,7 +1,46 @@+import { api, type ScoredHost } from '$lib/api';+import { match } from 'ts-pattern';import type { PageLoad } from './$types';+import { LIMIT_OPTIONS } from './conf';++export const load: PageLoad = async (req) => {+ const host = req.url.searchParams.get('site');+ let chosenHosts: string[] = req.url.searchParams.get('chosenHosts')?.split(',') || [];+ let errorMessage = false;++ let limit = LIMIT_OPTIONS[0];++ if (req.url.searchParams.get('limit')) {+ const userLimit = parseInt(req.url.searchParams.get('limit')!);+ limit = LIMIT_OPTIONS.includes(userLimit) ? userLimit : limit;+ }++ if (host && host.length > 0) {+ const res = await api.webgraphHostKnows({ host }).data;++ match(res)+ .with({ type: 'unknown' }, () => {+ errorMessage = true;+ })+ .with({ type: 'known' }, async ({ host }) => {+ if (host.length > 0 && !chosenHosts.includes(host)) chosenHosts = [...chosenHosts, host];+ })+ .exhaustive();+ }++ let similarHosts: ScoredHost[] = [];++ chosenHosts = chosenHosts.filter((host) => host.length > 0);++ if (chosenHosts.length > 0) {+ similarHosts = await api.webgraphHostSimilar({ hosts: chosenHosts, topN: limit }).data;+ }-export const load: PageLoad = () => {return {+ chosenHosts,+ errorMessage,+ similarHosts,+ limit,globals: {header: {divider: true,diff --git a/frontend/src/routes/explore/conf.ts b/frontend/src/routes/explore/conf.tsnew file mode 100644index 00000000..8dac91a6--- /dev/null+++ b/frontend/src/routes/explore/conf.ts@@ -0,0 +1 @@+export const LIMIT_OPTIONS = [10, 25, 50, 125, 250, 500, 1000];diff --git a/frontend/src/routes/privacy-and-happy-lawyers/README.md b/frontend/src/routes/privacy-and-happy-lawyers/README.mdindex 3275e716..91737171 100644--- a/frontend/src/routes/privacy-and-happy-lawyers/README.md+++ b/frontend/src/routes/privacy-and-happy-lawyers/README.md@@ -8,12 +8,10 @@ This keeps things simple, both for you and for us.Here is a brief overview of your privacy:- We don't store your IP address.-- We don't store any information that can be used to fingerprint your device,- browser etc.+- We don't store any information that can be used to fingerprint your device, browser etc.- We don't share any user data with any third parties.- We collect only the data needed to provide and improve the service.-- We serve all content directly from our servers to prevent tracking from third- parties.+- We serve all content directly from our servers to prevent tracking from third parties.- We use HTTPS encryption everywhere.By default, we do store some usage statistics in order to improve the search@@ -35,6 +33,16 @@ improve our services tremendously. You can opt-out of this at any time from theYou don't have to take our word for these claims as our[source code is available to everyone.](https://github.com/StractOrg/stract)+## Browser Features++Most of the site should function with only a minimal set of browser features enabled. We use javascript and some other browser features to optionally enhance the user experience in some places. We try to provide an overview here so you can optionally enable the features and functionality you want to use.++- [LocalStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) is used to store your optics and all other settings. The preferences that influence the search results, e.g. liked/disliked/blocked sites, gets send to the backend in the GET request parameters of your search.+- [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) is used in a number of places but we strive to solely use it to enhance the user experience. You should be able to perform searches and find similar sites in 'explore' without javascript enabled. Please [submit a bug report](https://github.com/StractOrg/stract/issues/new) if this is not the case so we can look into it. Javascript is however needed to provide functionality like changing your settings, liking/disliking sites, managing optics, easily remove a single site in 'explore' etc.+- [SSE](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) are used to stream the summary back to your browser when you request to summarize a search result.++We do not use any first-party, and especially not third-party, cookies.+## Terms of ServiceKeep in mind that all services provided in Stract are provided “as is” and there@@ -104,6 +112,10 @@ English language version, the English language version shall control.## Changelog+#### 10-03-2024:++Added overview of which browser features that are used.+#### 16-08-2023:No data is stored anymore when using Alice, so removed the section.