Commit 782dbb29d1

782dbb29d1ad3201fb5f74538344cc8d13d63031

parent: d650fd3b3e

Unsigned

Alicia Sykes <alicia@omg.lol> · 2024-02-24 10:05 UTC

Built smart search functionality

Layout: unified · split

web/src/components/Search.astro deleted −69
@@ -1,69 +0,0 @@
1---
2---
3
4<div class="search-wrap">
5 <label>What are you looking for?</label>
6 <div class="input-wrap">
7 <input class="search-input" type="text" placeholder="E.g. Password manager, browser, firewall" />
8 <button>🔎</button>
9 </div>
10
11</div>
12
13<style lang="scss">
14.search-wrap {
15
16 display: flex;
17 flex-direction: column;
18 width: 80%;
19 margin: 1rem auto;
20
21 label {
22 color: var(--foreground);
23 }
24
25 .input-wrap {
26 display: flex;
27 // gap: 1rem;
28 }
29
30 button {
31 padding: 0.2rem;
32 font-size: 2rem;
33 transform: translateX(-3rem);
34 border-radius: 0 8px 8px 0;
35 background: none;
36 border: none;
37
38 // background: var(--accent-fg);
39 // color: var(--accent-3);
40 // border: 2px solid var(--foreground);
41 // box-shadow: 6px 6px 0 var(--foreground);
42 // font-family: "Lekton", sans-serif;
43 // transition: all 0.2s ease-in-out;
44 }
45
46 input {
47
48 width: 100%;
49
50 padding: 0.2rem;
51 border-radius: 8px;
52
53 background: var(--accent-fg);
54 color: var(--accent-3);
55 border: 2px solid var(--foreground);
56 box-shadow: 6px 6px 0 var(--foreground);
57 font-family: "Rubik", sans-serif;
58 font-size: 1.6rem;
59 transition: all 0.2s ease-in-out;
60
61 &:focus {
62 outline: none;
63 border: 2px solid var(--accent-3);
64 box-shadow: 6px 6px 0 var(--accent-3);
65 color: var(--accent);
66 }
67 }
68}
69</style>
web/src/components/things/Search.svelte added +214
@@ -0,0 +1,214 @@
1<script lang="ts">
2 import { onMount } from 'svelte';
3 import Fuse from 'fuse.js';
4 import { slugify } from '@utils/fetch-data';
5 import type { Category, Section, Service, ShortService } from '../../types/Service';
6 import { formatLink } from '@utils/parse-markdown';
7 import { prepareSearchItems, searchOptions } from '@utils/do-searchy-searchy';
8
9 export let data: Category[];
10
11 let fuse: Fuse<any>;
12 let searchQuery = '';
13 let results: any[] = [];
14
15 // Initialize Fuse.js
16 onMount(() => {
17 const items = prepareSearchItems(data);
18 fuse = new Fuse(items, searchOptions);
19 });
20
21 const makeResultLink = (cat?: string, sec?: string, itm?: string) => {
22 if (!cat) return '/'
23 if (!sec) return `/${slugify(cat)}`
24 if (!itm) return `/${slugify(cat)}/${slugify(sec)}`
25 return `/${slugify(cat)}/${slugify(sec)}#${slugify(itm)}`;
26 };
27
28 const makeResultText = (cat?: string, sec?: string, itm?: string) => {
29 if (itm) return itm;
30 if (sec) return sec;
31 if (cat) return cat;
32 return '';
33 };
34
35 const makeLogoSrc = (logo: string, url: string) => {
36 if (!logo && !url) return '/broken-image.png';
37 return logo || `https://icon.horse/icon/${formatLink(url)}`;
38 };
39
40 const makeTitle = (typ: string, desc: string) => {
41 if (desc && typ === 'Service') {
42 return `${desc.slice(0, 60)}...`
43 }
44 return '';
45 };
46
47 function handleKeyDown(event: KeyboardEvent) {
48 if (event.key === 'Enter') {
49 event.preventDefault();
50 if (window) {
51 window.location.href = `/search/${encodeURIComponent(searchQuery)}`;
52 }
53 }
54 if (event.key === 'Escape') {
55 searchQuery = '';
56 }
57 }
58
59 // Watch for changes in the search query and update results
60 $: if (searchQuery) {
61 results = fuse.search(searchQuery).map(result => result.item).splice(0, 25);
62 } else {
63 results = [];
64 }
65</script>
66
67<div class="search-wrap">
68 <label for="search">
69 What are you looking for?
70 {#if searchQuery.length > 0}
71 <span class="enter-hint">Press enter to view all results</span>
72 {/if}
73 </label>
74 <input
75 id="search"
76 placeholder="Start typing..."
77 autocomplete="off"
78 bind:value={searchQuery}
79 on:keydown={handleKeyDown}
80 />
81
82
83 {#if searchQuery.length > 0}
84 <div class="suggestions">
85 <ul>
86 {#each results as result}
87 <li class="result-row">
88 <a
89 href={makeResultLink(result.category, result.sectionName, result.name)}
90 title={makeTitle(result.type, result.description)}
91 >
92 <span class="name">
93 {#if result.type === 'Service'}
94 <img src={makeLogoSrc(result.logo, result.url)} alt={result.name} width="20" height="20" loading="lazy" />
95 {/if}
96
97 {makeResultText(result.category, result.sectionName, result.name)}
98
99 {#if result.itemCount}
100 <i>({result.itemCount})</i>
101 {/if}
102 </span>
103 <span class="path">
104 {result.category ? `${result.category}` : ''}
105 {result.sectionName ? `➔ ${result.sectionName}` : ''}
106 {result.name ? `➔ ${result.name}` : ''}
107 </span>
108 </a>
109 </li>
110 {/each}
111 </ul>
112 </div>
113 {/if}
114</div>
115
116<style lang="scss">
117
118.search-wrap {
119 display: flex;
120 flex-direction: column;
121 position: relative;
122 margin: 1rem auto;
123 max-width: 900px;
124 margin: 0 auto;
125 width: 80vw;
126 label {
127 margin: 0.5rem 0;
128 display: flex;
129 justify-content: space-between;
130 align-items: center;
131 flex-wrap: wrap;
132 .enter-hint {
133 font-size:0.8rem;
134 opacity: 0.7;
135 }
136 }
137
138 input {
139 padding: 0.5rem 1rem;
140 font-size: 1.8rem;
141 border: 2px solid var(--foreground);
142 border-radius: var(--curve-lg);
143 box-shadow: 3px 3px 0 var(--foreground);
144 z-index: 4;
145 &:focus {
146 outline: none;
147 border-color: var(--accent);
148 box-shadow: 3px 3px 0 var(--accent);
149 }
150 }
151
152 .suggestions {
153 ul {
154 position: absolute;
155 background: white;
156 z-index: 3;
157 width: 100%;
158
159 list-style: none;
160 padding: 0;
161 margin: 0;
162 border: 2px solid var(--foreground);
163 border-radius: 0 0 var(--curve-lg) var(--curve-lg);
164 box-shadow: 3px 3px 0 var(--foreground);
165 transform: translateY(-0.5rem);
166 max-height: 500px;
167 overflow-y: scroll;
168
169 li.result-row {
170 padding: 0.5rem 1rem;
171 margin: 0.5rem 0;
172 a {
173 color: var(--foreground);
174 text-decoration: none;
175 display: flex;
176 justify-content: space-between;
177 flex-wrap: wrap;
178 .name {
179 display: flex;
180 align-items: center;
181 gap: 0.5rem;
182 i {
183 color: var(--accent);
184 font-weight: bold;
185 font-style: normal;
186 }
187 img {
188 border-radius: var(--curve-md);
189 width: 1.25rem;
190 height: 1.25rem;
191 font-size: 10px;
192 color: var(--accent);
193 overflow: hidden;
194 background: #f453974d;
195 padding: 1px;
196 }
197 }
198 .path {
199 font-size: 0.85rem;
200 opacity: 0.7;
201 }
202 }
203 &:hover {
204 background: var(--accent);
205 .name i {
206 color: var(--accent-fg);
207 }
208 }
209 }
210 }
211 }
212}
213
214</style>
web/src/components/things/ServiceList.astro +2 −1
@@ -4,6 +4,7 @@ import Button from '@components/form/Button.astro';
44import { parseMarkdown, formatLink } from '@utils/parse-markdown';
55import type { Service } from 'src/types/Service';
66import FontAwesome from '@components/form/FontAwesome.svelte';
7import { slugify } from '@utils/fetch-data';
78
89import GitHubMetrics from '@components/things/ItemGitHubMetrics.astro';
910
@@ -33,7 +34,7 @@ const { services, subHeading, buttonLink, noGitHubMetrics } = Astro.props;
3334 {services ? (
3435 <ul>
3536 {services.map((service: Service) => (
36 <li>
37 <li id={slugify(service.name)}>
3738 <div class="service-head">
3839 <img
3940 width="40"
web/src/components/things/SmartSuggestions.svelte added +140
@@ -0,0 +1,140 @@
1<script lang="ts">
2 import { onMount } from "svelte";
3 import { writable } from "svelte/store"; // Import writable to create a reactive variable
4 import type { Category, Service } from "../../types/Service";
5 import { parseMarkdown, formatLink } from '@utils/parse-markdown';
6 import { slugify } from '@utils/fetch-data';
7
8 interface ServiceResult extends Service {
9 path: string;
10 }
11
12 export let categories: Category[];
13 export let searchTerm: string;
14
15 let results = writable<ServiceResult[]>([]);
16
17 onMount(async () => {
18
19 const apiEndpoint = `https://awesome-privacy.as93.workers.dev/${searchTerm}`;
20 const fetchedServices = await fetch(apiEndpoint)
21 .then((response) => response.json())
22 .then((data) => {
23 console.log("SmartSuggestions data", data);
24 return JSON.parse(data);
25 });
26
27 const tmpResults: ServiceResult[] = [];
28 categories.forEach((category) => {
29 (category.sections || []).forEach((section) => {
30 (section.services || []).forEach((service) => {
31 if (fetchedServices.includes(service.name)) {
32 const path = `/${slugify(category.name)}/${slugify(section.name)}#${slugify(service.name)}`
33 tmpResults.push({ ...service, path });
34 return;
35 }
36 });
37 });
38 });
39 results.set(tmpResults);
40 });
41</script>
42
43{#if $results.length === 1}
44 <h3>Top Result</h3>
45{/if}
46{#if $results.length > 1}
47 <h3>Top Results</h3>
48{/if}
49 <section>
50 {#each $results as service (service)}
51 <a class="service-result" href={service.path}>
52 <div class="service-head">
53 <img
54 width="40"
55 height="40"
56 loading="lazy"
57 decoding="async"
58 class="service-icon"
59 alt={`${service.name} Icon`}
60 data-service-url={formatLink(service.url)}
61 src={service.icon || `https://icon.horse/icon/${formatLink(service.url)}`}
62 />
63 <div>
64 <h4>
65 {service.name}
66 {#if service.followWith}
67 <p class="follow-with">({service.followWith})</p>
68 {/if}
69 </h4>
70 <a class="service-link" href={service.url}>{formatLink(service.url)}</a>
71 </div>
72 </div>
73 </a>
74 {/each}
75 </section>
76
77
78
79<style lang="scss">
80 h3 {
81 width: 80vw;
82 max-width: 900px;
83 margin: 1rem auto;
84 color: var(--accent-3);
85 font-size: 1.6rem;
86 }
87 section {
88 display: grid;
89 grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
90 gap: 1rem;
91 width: 80vw;
92 max-width: 900px;
93 margin: 0 auto;
94 .service-result {
95 background: var(--accent-fg);
96 padding: 1rem;
97 border-radius: var(--curve-sm);
98 border: 1px solid var(--foreground);
99 box-shadow: 3px 3px 0 var(--foreground);
100 color: var(--foreground);
101 text-decoration: none;
102
103 .service-head {
104 display: flex;
105 align-items: center;
106 gap: 0.5rem;
107 h4 {
108 margin: 0;
109 font-size: 1.6rem;
110 display: flex;
111 align-items: center;
112 gap: 0.5rem;
113 .follow-with {
114 opacity: 0.7;
115 font-style: italic;
116 margin: 0;
117 font-size: 0.85rem;
118 font-weight: 400;
119 }
120 }
121 .service-icon {
122 width: 2.5rem;
123 height: 2.5rem;
124 border-radius: var(--curve-sm);
125
126 font-size: 10px;
127 overflow: hidden;
128 color: var(--accent);
129 }
130
131 .service-link {
132 max-width: 300px;
133 text-overflow: ellipsis;
134 overflow: hidden;
135 white-space: nowrap;
136 }
137 }
138 }
139 }
140</style>
web/src/layouts/Layout.astro +4 −1
@@ -1,5 +1,5 @@
11---
2
2import { ViewTransitions } from 'astro:transitions'
33import NavBar from '@components/scafold/NavBar.astro';
44import Footer from '@components/scafold/Footer.astro';
55
@@ -24,6 +24,9 @@ const {
2424<!doctype html>
2525<html lang="en">
2626 <head>
27
28 <ViewTransitions />
29
2730 <!-- Core info -->
2831 <title>{title}</title>
2932 <meta name="description" content={description}>
web/src/pages/[...section].astro +25 −26
@@ -34,11 +34,11 @@ const makeKeyWordTag = () => {
3434 const keywords = [];
3535 keywords.push(`free and open source ${title} software`);
3636 keywords.push(`private ${title} comparison`);
37 alternativeTo?.forEach((alt: string) => {
37 (alternativeTo || []).forEach((alt: string) => {
3838 keywords.push(`privacy-respecting ${alt} alternative`);
3939 keywords.push(`free open source ${alt} alternative`);
4040 });
41 services.forEach((serv: Service) => {
41 (services || []).forEach((serv: Service) => {
4242 keywords.push(serv.name);
4343 });
4444 keywords.push('ad free');
@@ -59,7 +59,7 @@ const makePageTitle = () => {
5959 */
6060const makeDescriptionTag = () => {
6161 let description = `A list of privacy respecting ${title}. `;
62 if (services.length > 0) {
62 if (services && services.length > 0) {
6363 const serviceList = services.map((serv: Service) => serv.name);
6464 description += `Compare ${serviceList.join(', ')} and more private apps and services. `
6565 } else {
@@ -71,31 +71,30 @@ const makeDescriptionTag = () => {
7171};
7272
7373export async function getStaticPaths() {
74
75const pages = await fetchData().then((data) => {
76 const results: Array<Props> = [];
77 if (!data || !data.categories) return results;
78 (data as AwesomePrivacy).categories.forEach((category) => {
79 const sections = category.sections.map((section) => ({
80 slug: `${slugify(category.name)}/${slugify(section.name)}`,
81 title: section.name,
82 services: section.services,
83 intro: section.intro,
84 notableMentions: section.notableMentions,
85 furtherInfo: section.furtherInfo,
86 wordOfWarning: section.wordOfWarning,
87 alternativeTo: section.alternativeTo,
88 categoryName: category.name,
89 otherSections: category.sections,
90 }));
91 results.push(...sections);
74 const pages = await fetchData().then((data) => {
75 const results: Array<Props> = [];
76 if (!data || !data.categories) return results;
77 (data as AwesomePrivacy).categories.forEach((category) => {
78 const sections = category.sections.map((section) => ({
79 slug: `${slugify(category.name)}/${slugify(section.name)}`,
80 title: section.name,
81 services: section.services,
82 intro: section.intro,
83 notableMentions: section.notableMentions,
84 furtherInfo: section.furtherInfo,
85 wordOfWarning: section.wordOfWarning,
86 alternativeTo: section.alternativeTo,
87 categoryName: category.name,
88 otherSections: category.sections,
89 }));
90 results.push(...sections);
91 });
92 return results;
9293 });
93 return results;
94});
9594
96return pages.map((props: Props) => {
97 return {params: { section: props.slug }, props };
98});
95 return pages.map((props: Props) => {
96 return {params: { section: props.slug }, props };
97 });
9998}
10099
101100const makePaginationLinks = () => {
web/src/pages/browse.astro +45 −3
@@ -4,8 +4,9 @@ import Layout from '@layouts/Layout.astro';
44import SectionList from '@components/things/SectionList.astro';
55
66import { fetchData } from '@utils/fetch-data';
7import { Category } from '../types/Service';
78
8const categories = (await fetchData())?.categories;
9const categories: Category[] = (await fetchData())?.categories;
910
1011---
1112
@@ -13,7 +14,10 @@ const categories = (await fetchData())?.categories;
1314
1415<div class="head-wrap">
1516 <h2>Browse</h2>
16 <input type="search" placeholder="Start typing to filter..." />
17 <span>
18 <input id="searchInput" type="search" placeholder="Start typing to filter..." />
19 <p id="press-enter-msg" class="press-enter">Press enter for deep search</p>
20 </span>
1721</div>
1822
1923<ul class="categories">
@@ -33,10 +37,16 @@ const categories = (await fetchData())?.categories;
3337<script>
3438 const filterInput = document.querySelector('input');
3539 const categories = document.querySelectorAll('.category');
40 const pressEnterMsg = document.getElementById('press-enter-msg');
3641
3742 filterInput?.addEventListener('input', (e) => {
3843 let resultsCount = 0;
3944 const filter = e.target.value.toLowerCase();
45 if (filter.length > 0) {
46 pressEnterMsg.style.visibility = 'visible';
47 } else {
48 pressEnterMsg.style.visibility = 'hidden';
49 }
4050 categories.forEach((category) => {
4151 const title = category.querySelector('.category-title').textContent.toLowerCase();
4252 const sections = category.querySelectorAll('.section');
@@ -61,6 +71,33 @@ const categories = (await fetchData())?.categories;
6171 const noResults = document.querySelector('.no-results');
6272 noResults.style.display = resultsCount === 0 ? 'block' : 'none';
6373 });
74
75 if (typeof window !== 'undefined') {
76 document.addEventListener('DOMContentLoaded', function() {
77 const searchInput = document.getElementById('searchInput') as HTMLInputElement | null;
78 if (searchInput === null) return;
79 searchInput.addEventListener('keydown', function(event) {
80 console.log('Keydown', event.key);
81 if (event.key === 'Enter') {
82 event.preventDefault();
83 const searchTerm = encodeURIComponent(searchInput.value);
84 window.location.href = `/search/${searchTerm}`;
85 }
86 if (event.key === 'Escape') {
87 searchInput.value = '';
88 searchInput.blur();
89 pressEnterMsg.style.visibility = 'hidden';
90 categories.forEach((category) => {
91 category.style.display = 'inline-flex';
92 const sections = category.querySelectorAll('.section');
93 sections.forEach((section) => {
94 section.style.display = 'block';
95 });
96 });
97 }
98 });
99 });
100 }
64101</script>
65102
66103
@@ -73,6 +110,11 @@ const categories = (await fetchData())?.categories;
73110 align-items: center;
74111 justify-content: space-between;
75112 flex-wrap: wrap;
113 .press-enter {
114 margin: 0.5rem 0 0 0;
115 opacity: 0.5;
116 visibility: hidden;
117 }
76118 input {
77119 padding: 0.5rem;
78120 border: 2px solid var(--foreground);
@@ -116,7 +158,7 @@ const categories = (await fetchData())?.categories;
116158 margin: 0 auto;
117159 width: 85vw;
118160 max-width: 1800px;
119 padding: 2rem 0;
161 padding: 1rem 0 2rem 0;
120162 .category {
121163 background: var(--accent-fg);
122164 border: 2px solid var(--foreground);
web/src/pages/index.astro +2 −2
@@ -3,7 +3,7 @@
33import Layout from '@layouts/Layout.astro';
44import Card from '@components/Card.astro';
55import Hero from '@components/Hero.astro';
6import Search from '@components/Search.astro';
6import Search from '@components/things/Search.svelte';
77import SectionList from '@components/things/SectionList.astro';
88
99import { fetchData } from '@utils/fetch-data';
@@ -26,7 +26,7 @@ const description = 'Privacy is a fundamental human right; '
2626 <h2>
2727 <a href="/search">Search</a>
2828 </h2>
29 <Search />
29 <Search client:visible data={categories} />
3030 <h2 class="browse-title"><a href="/browse">Browse</a></h2>
3131 <ul class="categories">
3232 {categories.map((category) => (
web/src/pages/search/[...searchTerm].astro added +200
@@ -0,0 +1,200 @@
1---
2 import Fuse from 'fuse.js';
3
4import Layout from '@layouts/Layout.astro';
5import Buton from '@components/form/Button.astro';
6import { fetchData, slugify } from '@utils/fetch-data';
7import { prepareSearchItems, searchOptions } from '@utils/do-searchy-searchy';
8import Search from '@components/things/Search.svelte';
9import SmartSuggestions from '@components/things/SmartSuggestions.svelte';
10import FontAwesome from '@components/form/FontAwesome.svelte';
11
12import type { Service } from '../../types/Service';
13
14export const prerender = false;
15
16let fuse: Fuse<any>;
17
18const categories = (await fetchData())?.categories;
19
20const items = prepareSearchItems(categories);
21
22fuse = new Fuse(items, searchOptions);
23
24const searchTerm = Astro.params.searchTerm;
25
26const searchResults = fuse.search(searchTerm || '').map(result => result.item);
27
28const services = searchResults.filter(result => result.type === 'Service');
29
30interface RenderResults {
31 categoryName: string;
32 sections: {
33 sectionName: string;
34 items: Service;
35 }
36};
37
38const putResultsIntoGroups = () => {
39 const grouped = services.reduce((acc, item) => {
40 const { category: categoryName, sectionName, ...service } = item;
41
42 if (!acc[categoryName]) {
43 acc[categoryName] = { categoryName, sections: {} };
44 }
45
46 if (!acc[categoryName].sections[sectionName]) {
47 acc[categoryName].sections[sectionName] = { sectionName, items: [] };
48 }
49
50 acc[categoryName].sections[sectionName].items.push(service);
51
52 return acc;
53 }, {});
54
55 // Convert the grouped object into the desired array structure
56 return Object.values(grouped).map(category => ({
57 categoryName: category.categoryName,
58 sections: Object.values(category.sections)
59 }));
60};
61
62const beer = putResultsIntoGroups();
63
64---
65
66<Layout title="Search | Awesome Privacy">
67 <section>
68 <h1>Search</h1>
69 <Search client:visible data={categories} />
70 </section>
71 <SmartSuggestions client:visible searchTerm={searchTerm} categories={categories} />
72 <section class="result-count">
73 <h3>Deep Search</h3>
74 <p>Showing {services.length} results for "{searchTerm}" sorted by relevence</p>
75 </section>
76 <div class="results">
77 {
78 beer.map((category: any) => (
79 <div class="category">
80 <a class="category-title" href={`/${slugify(category.categoryName)}`}>
81 <h3>{category.categoryName}</h3>
82 </a>
83 <span class="section-icon"><FontAwesome iconName={slugify(category.categoryName)} /></span>
84 <ul class="section-list">
85 {category.sections.map(section => (
86 <li class="section-item">
87 <h4>{section.sectionName}</h4>
88 <ul class="service-list">
89 {section.items.map(item => (
90 <li>
91 <a href={item.url}>{item.name}</a>
92 </li>
93 ))}
94 </ul>
95 </li>
96 ))}
97 </ul>
98 </div>
99 ))
100 }
101</div>
102</Layout>
103
104
105<style lang="scss">
106
107section {
108 display: flex;
109 flex-direction: column;
110 padding: 1rem;
111 margin: 2rem auto;
112 padding: 1rem;
113 width: calc(100% - 2rem);
114 max-width: 1100px;
115
116 h1 {
117 font-size: 3rem;
118 color: var(--accent-3);
119 font-family: "Lekton", sans-serif;
120 text-align: center;
121 margin: 1rem 0;
122 }
123}
124
125.result-count {
126 padding: 0;
127 width: 80vw;
128 max-width: 900px;
129 margin: 1rem auto 0 auto;
130 h3 {
131 margin: 0;
132 color: var(--accent-3);
133 font-size: 1.6rem;
134 }
135 p {
136 margin: 0;
137 opacity: 0.6;
138 }
139}
140
141.results {
142 margin: 0 auto 2rem auto;
143 padding: 1rem;
144 width: calc(100% - 2rem);
145 max-width: 1100px;
146 columns: 6 300px;
147 column-gap: 1rem;
148 .category {
149 padding: 1rem;
150 box-shadow: 4px 4px 0 var(--foreground);
151 background: var(--accent-fg);
152 border: 2px solid var(--foreground);
153 border-radius: var(--curve-sm);
154 display: inline-flex;
155 flex-direction: column;
156 width: 85%;
157 margin: 1rem;
158 position: relative;
159 .category-title {
160 text-decoration: none;
161 color: var(--foreground);
162 z-index: 2;
163 position: relative;
164 h3 {
165 font-family: "Lekton", sans-serif;
166 font-weight: bold;
167 margin: 0;
168 font-size: 1.8rem;
169 }
170 }
171 .section-icon {
172 position: absolute;
173 right: 0.5rem;
174 top: 0.5rem;
175 width: fit-content;
176 :global(svg) {
177 width: 2rem;
178 height: 2rem;
179 opacity: 0.5;
180 text-shadow: 3px 3px 0 black;
181 color: var(--accent-3);
182 transition: all 0.2s ease-in-out;
183 }
184 }
185 .section-list {
186 list-style: none;
187 padding: 0;
188 margin: 0;
189 h4 {
190 margin: 1rem 0 0 0;
191 }
192 .service-list {
193 list-style: none;
194 padding: 0;
195 margin: 0;
196 }
197 }
198 }
199}
200</style>
web/src/pages/search/index.astro added +45
@@ -0,0 +1,45 @@
1---
2
3import Layout from '@layouts/Layout.astro';
4import Buton from '@components/form/Button.astro';
5import { fetchData } from '@utils/fetch-data';
6
7import Search from '@components/things/Search.svelte';
8
9const categories = (await fetchData())?.categories;
10
11---
12
13<Layout title="Search | Awesome Privacy">
14 <section>
15 <h1>Search</h1>
16 <Search client:visible data={categories} />
17 </section>
18</Layout>
19
20
21<style lang="scss">
22
23section {
24 display: flex;
25 flex-direction: column;
26 padding: 1rem;
27 box-shadow: 4px 4px 0 var(--foreground);
28 background: var(--accent-fg);
29 border: 2px solid var(--foreground);
30 border-radius: var(--curve-sm);
31 margin: 2rem auto;
32 padding: 1rem;
33 width: calc(100% - 2rem);
34 max-width: 1100px;
35 min-height: 80vh;
36
37 h1 {
38 font-size: 3rem;
39 color: var(--accent-3);
40 font-family: "Lekton", sans-serif;
41 text-align: center;
42 margin: 1rem 0;
43 }
44}
45</style>
web/src/types/Service.ts +4 −4
@@ -28,12 +28,12 @@ export interface Section {
2828 alternativeTo?: string[];
2929}
3030
31export interface ServiceStats {
32 isOpenSource: boolean;
33 author: string;
34 authorUrl: string;
31export interface Category {
32 name: string;
33 sections: Section[];
3534}
3635
36
3737export interface AwesomePrivacy {
3838 categories: Array<{
3939 name: string;
web/src/utils/do-searchy-searchy.ts added +61
@@ -0,0 +1,61 @@
1import Fuse from 'fuse.js';
2// import { slugify } from '@utils/fetch-data';
3import type { Category, Section, Service, ShortService } from '../types/Service';
4// import { formatLink } from '@utils/parse-markdown';
5
6export const prepareSearchItems = (categories: Category[]) => {
7 const items: any = [];
8 // Add each category
9 categories.forEach(category => {
10 items.push({
11 type: 'Category',
12 category: category.name,
13 itemCount: (category.sections || []).reduce((acc, section) => {
14 return acc + (section.services || []).length;
15 }, 0),
16 });
17
18 // Add section with category context
19 category.sections.forEach(section => {
20 items.push({
21 type: 'Section',
22 sectionName: section.name,
23 description: section.intro || '',
24 category: category.name,
25 itemCount: (section.services || []).length,
26 });
27
28 // Add service with section and category context
29 (section.services || []).forEach(service => {
30 items.push({
31 type: 'Service',
32 name: service.name,
33 description: service.description,
34 url: service.url,
35 github: service.github || '',
36 category: category.name,
37 sectionName: section.name,
38 logo: service.icon || '',
39 });
40 });
41 });
42 });
43 return items;
44};
45
46export const searchOptions = {
47 includeScore: true,
48 keys: [
49 { name: 'name', weight: 0.9 },
50 { name: 'sectionName', weight: 0.8 },
51 { name: 'category', weight: 0.7 },
52 { name: 'notableMentions', weight: 0.5 },
53 { name: 'alternativeTo', weight: 0.5 },
54 { name: 'github', weight: 0.4 },
55 { name: 'url', weight: 0.2 },
56 { name: 'description', weight: 0.1 },
57 { name: 'intro', weight: 0.1 },
58 { name: 'furtherInfo', weight: 0.1 },
59 { name: 'wordOfWarning', weight: 0.1 },
60 ],
61};