Commit e1c0318d9b
Unsigned
Layout: unified · split
web/src/components/scafold/Footer.astro +7 −2
| @@ -1,8 +1,13 @@ | ||
| 1 | --- | |
| 2 | const year = new Date().getFullYear(); | |
| 3 | --- | |
| 4 | ||
| 1 | 5 | <footer> |
| 2 | 6 | <a href="/about">Awesome Privacy</a> is licensed under <a |
| 3 | href="https://github.com/Lissy93/awesome-privacy/blob/main/LICENSE">MIT</a | |
| 7 | href="https://github.com/Lissy93/awesome-privacy/blob/main/LICENSE" | |
| 8 | >CC0 1.0 Universal</a | |
| 4 | 9 | > |
| 5 | © <a href="https://aliciasykes.com">Alicia Sykes</a> 2024 | Source code available | |
| 10 | © <a href="https://aliciasykes.com">Alicia Sykes</a> 2018 - {year || 'Present'} | Source code available | |
| 6 | 11 | on <a href="https://github.com/Lissy93/awesome-privacy">GitHub</a> |
| 7 | 12 | </footer> |
| 8 | 13 | |
web/src/components/things/AddNewService.svelte +13 −5
| @@ -20,24 +20,31 @@ | ||
| 20 | 20 | const serviceCrypto = writable(false); |
| 21 | 21 | const additionalInfo = writable(''); |
| 22 | 22 | |
| 23 | let codeBlock: any; | |
| 23 | let codeBlock: HTMLElement | undefined; | |
| 24 | 24 | let interactiveActivated = false; |
| 25 | 25 | |
| 26 | 26 | $: (yamlText, updateHighlighting()); |
| 27 | 27 | |
| 28 | /* eslint-disable svelte/no-dom-manipulating -- hljs requires direct DOM access for syntax highlighting */ | |
| 28 | 29 | function updateHighlighting() { |
| 29 | 30 | if (codeBlock) { |
| 30 | 31 | codeBlock.textContent = yamlText; |
| 31 | 32 | codeBlock.dataset.highlighted && delete codeBlock.dataset.highlighted; |
| 32 | if (window && (window as any).hljs) { | |
| 33 | (window as any).hljs.highlightElement(codeBlock); | |
| 33 | const hljs = ( | |
| 34 | window as Window & { | |
| 35 | hljs?: { highlightElement: (el: HTMLElement) => void }; | |
| 36 | } | |
| 37 | ).hljs; | |
| 38 | if (hljs) { | |
| 39 | hljs.highlightElement(codeBlock); | |
| 34 | 40 | interactiveActivated = true; |
| 35 | 41 | } |
| 36 | 42 | } |
| 37 | 43 | } |
| 44 | /* eslint-enable svelte/no-dom-manipulating */ | |
| 38 | 45 | |
| 39 | const filterEmptyValues = (obj: Record<string, any>) => { | |
| 40 | const filteredObj: Record<string, any> = {}; | |
| 46 | const filterEmptyValues = (obj: Record<string, unknown>) => { | |
| 47 | const filteredObj: Record<string, unknown> = {}; | |
| 41 | 48 | Object.keys(obj).forEach((key) => { |
| 42 | 49 | if (obj[key] || ['name', 'url', 'icon', 'description'].includes(key)) { |
| 43 | 50 | filteredObj[key] = obj[key]; |
| @@ -397,6 +404,7 @@ | ||
| 397 | 404 | upon approval. |
| 398 | 405 | </p> |
| 399 | 406 | {#if !interactiveActivated || !codeBlock} |
| 407 | <!-- eslint-disable-next-line svelte/no-at-html-tags -- yamlText is generated from user form input via yaml.dump, not arbitrary HTML --> | |
| 400 | 408 | <pre><code class="language-yaml">{@html yamlText}</code></pre> |
| 401 | 409 | {/if} |
| 402 | 410 | <pre><code bind:this={codeBlock} class="language-yaml"></code></pre> |
web/src/components/things/AndroidDetailedInfo.astro +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | import type { AndroidInfo } from '@utils/fetch-android-info'; |
| 3 | import { formatDate, timeAgo } from '@utils/dates-n-stuff'; | |
| 3 | import { formatDate } from '@utils/dates-n-stuff'; | |
| 4 | 4 | import FontAwesome from '@components/form/FontAwesome.svelte'; |
| 5 | 5 | |
| 6 | 6 | interface Props { |
web/src/components/things/DiscordDetailedInfo.astro −2
| @@ -1,7 +1,5 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | import type { DiscordInfo } from '@utils/fetch-discord-info'; |
| 3 | import { formatDate, timeAgo } from '@utils/dates-n-stuff'; | |
| 4 | import FontAwesome from '@components/form/FontAwesome.svelte'; | |
| 5 | 3 | |
| 6 | 4 | interface Props { |
| 7 | 5 | discordData: DiscordInfo; |
web/src/components/things/IosAppDetailedInfo.astro +2 −2
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | |
| 3 | 3 | import type { IoSApiResponse } from '@utils/fetch-ios-info'; |
| 4 | import { formatDate, timeAgo } from '@utils/dates-n-stuff'; | |
| 4 | import { formatDate } from '@utils/dates-n-stuff'; | |
| 5 | 5 | import FontAwesome from "@components/form/FontAwesome.svelte" |
| 6 | 6 | |
| 7 | 7 | |
| @@ -18,7 +18,7 @@ const makeRatingPercentage = (rating: number) => (rating / 5) * 100; | ||
| 18 | 18 | |
| 19 | 19 | const roundRatings = (rating: number) => Math.round(rating * 100) / 100; |
| 20 | 20 | |
| 21 | const putCommaInNumber = (num: number | any) => { | |
| 21 | const putCommaInNumber = (num: number | string | undefined) => { | |
| 22 | 22 | if (!num) return 'Unknown'; |
| 23 | 23 | return typeof num === 'number' ? num.toLocaleString() : num; |
| 24 | 24 | } |
web/src/components/things/ItemGitHubMetrics.astro +14 −7
| @@ -2,13 +2,19 @@ | ||
| 2 | 2 | import FontAwesome from "@components/form/FontAwesome.svelte"; |
| 3 | 3 | const { github } = Astro.props; |
| 4 | 4 | |
| 5 | // const [user, repo] = github.split("/"); | |
| 5 | interface GitHubRepoData { | |
| 6 | stargazers_count?: number; | |
| 7 | forks_count?: number; | |
| 8 | open_issues_count?: number; | |
| 9 | language?: string; | |
| 10 | license?: { spdx_id?: string; name?: string }; | |
| 11 | } | |
| 6 | 12 | |
| 7 | 13 | /** |
| 8 | 14 | * For a given `user/repo` fetch repository stats from the GitHub API data |
| 9 | 15 | * If API key is available through env var, use it to increase rate limit |
| 10 | 16 | * Returns the response data and status code (200 == success) |
| 11 | * @param repo | |
| 17 | * @param repo | |
| 12 | 18 | */ |
| 13 | 19 | const fetchGitHubData = async (repo: string) => { |
| 14 | 20 | const apiKey = import.meta.env.GITHUB_API_KEY; |
| @@ -17,8 +23,8 @@ const fetchGitHubData = async (repo: string) => { | ||
| 17 | 23 | headers.append("Authorization", `token ${apiKey}`); |
| 18 | 24 | } |
| 19 | 25 | |
| 20 | let data = {}; | |
| 21 | let statusCode = 0; | |
| 26 | let data: GitHubRepoData = {}; | |
| 27 | let statusCode; | |
| 22 | 28 | |
| 23 | 29 | const response = await fetch(`https://api.github.com/repos/${repo}`, { |
| 24 | 30 | headers: headers, |
| @@ -50,7 +56,7 @@ const fetchGitHubData = async (repo: string) => { | ||
| 50 | 56 | * Given a license object, return SPDX ID, or a formatted name |
| 51 | 57 | * @param license |
| 52 | 58 | */ |
| 53 | const formatLicense = (license: { spdx_id?: string, name?: string }) => { | |
| 59 | const formatLicense = (license?: { spdx_id?: string, name?: string }) => { | |
| 54 | 60 | if (!license) { |
| 55 | 61 | return "Unknown"; |
| 56 | 62 | } |
| @@ -65,7 +71,8 @@ const formatLicense = (license: { spdx_id?: string, name?: string }) => { | ||
| 65 | 71 | * E.g. If greater than thousand, then return in k format |
| 66 | 72 | * @param num |
| 67 | 73 | */ |
| 68 | const formatBigNumber = (num: number) => { | |
| 74 | const formatBigNumber = (num: number | undefined) => { | |
| 75 | if (num == null) return 0; | |
| 69 | 76 | if (num > 1000) { |
| 70 | 77 | return `${(num / 1000).toFixed(1)}k`; |
| 71 | 78 | } |
| @@ -73,7 +80,7 @@ const formatBigNumber = (num: number) => { | ||
| 73 | 80 | } |
| 74 | 81 | |
| 75 | 82 | // Initiate GitHub fetch, and make available to the component |
| 76 | const stats = (await fetchGitHubData(github)) as any; | |
| 83 | const stats = await fetchGitHubData(github); | |
| 77 | 84 | |
| 78 | 85 | const { |
| 79 | 86 | stargazers_count, forks_count, open_issues_count, language, license, |
web/src/components/things/RedditDetailedInfo.astro +1 −2
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | import type { RedditData } from '@utils/fetch-reddit-info'; |
| 3 | import { timestampToDate, timeAgo } from '@utils/dates-n-stuff'; | |
| 4 | import FontAwesome from '@components/form/FontAwesome.svelte'; | |
| 3 | import { timestampToDate } from '@utils/dates-n-stuff'; | |
| 5 | 4 | |
| 6 | 5 | interface Props { |
| 7 | 6 | redditData: RedditData; |
web/src/components/things/SavedServices.svelte +1 −1
| @@ -48,7 +48,7 @@ | ||
| 48 | 48 | <div> |
| 49 | 49 | {#if $savedServices.length > 0} |
| 50 | 50 | <div class="saved-services"> |
| 51 | {#each $savedServices as thingy} | |
| 51 | {#each $savedServices as thingy (thingy.service.name + thingy.section)} | |
| 52 | 52 | <ServiceCard |
| 53 | 53 | categoryName={thingy.category} |
| 54 | 54 | sectionName={thingy.section} |
web/src/components/things/Search.svelte +5 −9
| @@ -2,21 +2,17 @@ | ||
| 2 | 2 | import { onMount } from 'svelte'; |
| 3 | 3 | import Fuse from 'fuse.js'; |
| 4 | 4 | import { slugify } from '@utils/fetch-data'; |
| 5 | import type { | |
| 6 | Category, | |
| 7 | Section, | |
| 8 | Service, | |
| 9 | ShortService, | |
| 10 | } from '../../types/Service'; | |
| 5 | import type { Category } from '../../types/Service'; | |
| 11 | 6 | import { formatLink } from '@utils/parse-markdown'; |
| 12 | 7 | import { prepareSearchItems, searchOptions } from '@utils/do-searchy-searchy'; |
| 8 | import type { SearchItem } from '@utils/do-searchy-searchy'; | |
| 13 | 9 | |
| 14 | 10 | export let data: Category[]; |
| 15 | 11 | export let previousSearch: string | undefined = undefined; |
| 16 | 12 | |
| 17 | let fuse: Fuse<any>; | |
| 13 | let fuse: Fuse<SearchItem>; | |
| 18 | 14 | let searchQuery = ''; |
| 19 | let results: any[] = []; | |
| 15 | let results: SearchItem[]; | |
| 20 | 16 | |
| 21 | 17 | // Initialize Fuse.js |
| 22 | 18 | onMount(() => { |
| @@ -91,7 +87,7 @@ | ||
| 91 | 87 | {#if searchQuery.length > 0} |
| 92 | 88 | <div class="suggestions"> |
| 93 | 89 | <ul> |
| 94 | {#each results as result} | |
| 90 | {#each results as result (result.name + result.category + result.sectionName)} | |
| 95 | 91 | <li class="result-row"> |
| 96 | 92 | <a |
| 97 | 93 | href={makeResultLink( |
web/src/components/things/ServiceCard.astro +1 −1
| @@ -92,5 +92,5 @@ const { service, sectionName, categoryName } = Astro.props; | ||
| 92 | 92 | </div> |
| 93 | 93 | |
| 94 | 94 | <style lang="scss"> |
| 95 | @import './service-card.scss'; | |
| 95 | @use './service-card.scss'; | |
| 96 | 96 | </style> |
web/src/components/things/ServiceCard.svelte +2 −1
| @@ -44,6 +44,7 @@ | ||
| 44 | 44 | src={service.icon || `https://icon.horse/icon/${formatLink(service.url)}`} |
| 45 | 45 | /> |
| 46 | 46 | <div class="service-body"> |
| 47 | <!-- eslint-disable-next-line svelte/no-at-html-tags -- description is from curated YAML data, not user input --> | |
| 47 | 48 | <p>{@html service.description}</p> |
| 48 | 49 | </div> |
| 49 | 50 | </div> |
| @@ -64,5 +65,5 @@ | ||
| 64 | 65 | </div> |
| 65 | 66 | |
| 66 | 67 | <style lang="scss"> |
| 67 | @import './service-card.scss'; | |
| 68 | @use './service-card.scss'; | |
| 68 | 69 | </style> |
web/src/layouts/Layout.astro +4 −1
| @@ -10,7 +10,7 @@ interface Props { | ||
| 10 | 10 | keywords?: string; // Overide keywords tag |
| 11 | 11 | hideNav?: boolean; // Don't show the navbar (just homepage) |
| 12 | 12 | author?: string; // Author of the content |
| 13 | customSchemaJson?: any; // Custom schema item | |
| 13 | customSchemaJson?: Record<string, unknown>; // Custom schema item | |
| 14 | 14 | breadcrumbs?: Array<{ |
| 15 | 15 | name: string; |
| 16 | 16 | item: string; |
| @@ -121,6 +121,7 @@ const makeSearchLd = () => { | ||
| 121 | 121 | { |
| 122 | 122 | breadcrumbs && ( |
| 123 | 123 | <script |
| 124 | is:inline | |
| 124 | 125 | type="application/ld+json" |
| 125 | 126 | set:html={JSON.stringify(makeBreadcrumbs())} |
| 126 | 127 | /> |
| @@ -129,12 +130,14 @@ const makeSearchLd = () => { | ||
| 129 | 130 | { |
| 130 | 131 | customSchemaJson && ( |
| 131 | 132 | <script |
| 133 | is:inline | |
| 132 | 134 | type="application/ld+json" |
| 133 | 135 | set:html={JSON.stringify(customSchemaJson)} |
| 134 | 136 | /> |
| 135 | 137 | ) |
| 136 | 138 | } |
| 137 | 139 | <script |
| 140 | is:inline | |
| 138 | 141 | type="application/ld+json" |
| 139 | 142 | set:html={JSON.stringify(makeSearchLd)} |
| 140 | 143 | /> |
web/src/pages/about.astro +75 −31
| @@ -12,25 +12,44 @@ import { | ||
| 12 | 12 | appDescription, |
| 13 | 13 | } from '../site-config'; |
| 14 | 14 | |
| 15 | const contributorsResource = async () => { | |
| 15 | interface GitHubContributor { | |
| 16 | login: string; | |
| 17 | avatar_url: string; | |
| 18 | html_url: string; | |
| 19 | } | |
| 20 | ||
| 21 | interface Sponsor { | |
| 22 | login: string; | |
| 23 | avatarUrl: string; | |
| 24 | name?: string; | |
| 25 | } | |
| 26 | ||
| 27 | const githubHeaders: Record<string, string> = { | |
| 28 | 'User-Agent': 'awesome-privacy', | |
| 29 | }; | |
| 30 | const apiKey = import.meta.env.GITHUB_API_KEY; | |
| 31 | if (apiKey) { | |
| 32 | githubHeaders['Authorization'] = `Bearer ${apiKey}`; | |
| 33 | } | |
| 34 | ||
| 35 | const contributorsResource = async (): Promise<GitHubContributor[] | null> => { | |
| 16 | 36 | const url = |
| 17 | 37 | 'https://api.github.com/repos/lissy93/personal-security-checklist/contributors?per_page=100'; |
| 18 | const response = await fetch(url); | |
| 19 | if (!response.ok) { | |
| 20 | throw new Error('Failed to fetch contributors'); | |
| 21 | } | |
| 38 | const response = await fetch(url, { headers: githubHeaders }); | |
| 39 | if (!response.ok) return null; | |
| 22 | 40 | return await response.json(); |
| 23 | 41 | }; |
| 24 | 42 | |
| 25 | const sponsorsResource = async () => { | |
| 43 | const sponsorsResource = async (): Promise<Sponsor[] | null> => { | |
| 26 | 44 | const url = 'https://github-sponsors.as93.workers.dev/lissy93'; |
| 27 | 45 | const response = await fetch(url); |
| 28 | if (!response.ok) { | |
| 29 | throw new Error('Failed to fetch sponsors'); | |
| 30 | } | |
| 46 | if (!response.ok) return null; | |
| 31 | 47 | return await response.json(); |
| 32 | 48 | }; |
| 33 | 49 | |
| 50 | const contributors = await contributorsResource(); | |
| 51 | const sponsors = await sponsorsResource(); | |
| 52 | ||
| 34 | 53 | const licenseContent = async () => { |
| 35 | 54 | const url = |
| 36 | 55 | 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/HEAD/LICENSE'; |
| @@ -98,10 +117,10 @@ const licenseContent = async () => { | ||
| 98 | 117 | <h2 id="acknowledgements">Acknowledgements</h2> |
| 99 | 118 | <h3 id="sponsors">Sponsors</h3> |
| 100 | 119 | <p>Huge thanks to the following sponsors, for their ongoing support 💖</p> |
| 101 | <div class="user-list"> | |
| 102 | { | |
| 103 | sponsorsResource().then((sponsors) => { | |
| 104 | return sponsors.map((sponsor: any) => ( | |
| 120 | { | |
| 121 | sponsors ? ( | |
| 122 | <div class="user-list"> | |
| 123 | {sponsors.map((sponsor) => ( | |
| 105 | 124 | <a |
| 106 | 125 | class="user" |
| 107 | 126 | href={`https://github.com/${sponsor.login}`} |
| @@ -111,10 +130,16 @@ const licenseContent = async () => { | ||
| 111 | 130 | <img src={sponsor.avatarUrl} alt={sponsor.login} /> |
| 112 | 131 | <p>{sponsor.name || sponsor.login}</p> |
| 113 | 132 | </a> |
| 114 | )); | |
| 115 | }) | |
| 116 | } | |
| 117 | </div> | |
| 133 | ))} | |
| 134 | </div> | |
| 135 | ) : ( | |
| 136 | <img | |
| 137 | class="fallback-img" | |
| 138 | src="https://readme-contribs.as93.net/sponsors/lissy93?perRow=12&shape=squircle&textColor=ffffff&limit=96" | |
| 139 | alt="Sponsors" | |
| 140 | /> | |
| 141 | ) | |
| 142 | } | |
| 118 | 143 | |
| 119 | 144 | <h3 id="contributors">Contributors</h3> |
| 120 | 145 | <p> |
| @@ -122,23 +147,29 @@ const licenseContent = async () => { | ||
| 122 | 147 | maintain it.<br /> |
| 123 | 148 | Special thanks to the below, top-100 contributors 🌟 |
| 124 | 149 | </p> |
| 125 | <div class="user-list"> | |
| 126 | { | |
| 127 | contributorsResource().then((sponsors) => { | |
| 128 | return sponsors.map((sponsor: any) => ( | |
| 150 | { | |
| 151 | contributors ? ( | |
| 152 | <div class="user-list"> | |
| 153 | {contributors.map((contributor) => ( | |
| 129 | 154 | <a |
| 130 | 155 | class="user" |
| 131 | href={sponsor.html_url} | |
| 156 | href={contributor.html_url} | |
| 132 | 157 | target="_blank" |
| 133 | 158 | rel="noreferrer" |
| 134 | 159 | > |
| 135 | <img src={sponsor.avatar_url} alt={sponsor.login} /> | |
| 136 | <p>{sponsor.login}</p> | |
| 160 | <img src={contributor.avatar_url} alt={contributor.login} /> | |
| 161 | <p>{contributor.login}</p> | |
| 137 | 162 | </a> |
| 138 | )); | |
| 139 | }) | |
| 140 | } | |
| 141 | </div> | |
| 163 | ))} | |
| 164 | </div> | |
| 165 | ) : ( | |
| 166 | <img | |
| 167 | class="fallback-img" | |
| 168 | src="https://readme-contribs.as93.net/contributors/lissy93/awesome-privacy?perRow=12&shape=squircle&textColor=ffffff&limit=96" | |
| 169 | alt="Contributors" | |
| 170 | /> | |
| 171 | ) | |
| 172 | } | |
| 142 | 173 | |
| 143 | 174 | <hr /> |
| 144 | 175 | |
| @@ -281,7 +312,7 @@ const licenseContent = async () => { | ||
| 281 | 312 | <style lang="scss"> |
| 282 | 313 | h2 { |
| 283 | 314 | font-size: 2rem; |
| 284 | margin: 2rem 0 1rem 0; | |
| 315 | margin: 1rem 0 0.5rem 0; | |
| 285 | 316 | } |
| 286 | 317 | p { |
| 287 | 318 | font-size: 1.2rem; |
| @@ -343,18 +374,25 @@ const licenseContent = async () => { | ||
| 343 | 374 | .user-list { |
| 344 | 375 | display: flex; |
| 345 | 376 | flex-wrap: wrap; |
| 346 | gap: 1rem; | |
| 377 | gap: 0.25rem; | |
| 347 | 378 | margin: 2rem 0; |
| 348 | 379 | .user { |
| 349 | 380 | width: 6rem; |
| 350 | 381 | overflow: hidden; |
| 351 | 382 | text-align: center; |
| 383 | padding: 0.5rem; | |
| 384 | border-radius: var(--curve-sm); | |
| 385 | transition: background 0.2s ease-in-out; | |
| 386 | &:hover { | |
| 387 | background: var(--background-form); | |
| 388 | } | |
| 352 | 389 | img { |
| 353 | 390 | width: 5rem; |
| 354 | 391 | height: 5rem; |
| 355 | 392 | border-radius: var(--curve-md); |
| 356 | 393 | } |
| 357 | 394 | p { |
| 395 | margin: 0.5rem auto 0 auto; | |
| 358 | 396 | font-size: 1rem; |
| 359 | 397 | display: -webkit-box; |
| 360 | 398 | -webkit-line-clamp: 1; |
| @@ -364,6 +402,12 @@ const licenseContent = async () => { | ||
| 364 | 402 | } |
| 365 | 403 | } |
| 366 | 404 | |
| 405 | .fallback-img { | |
| 406 | max-width: 100%; | |
| 407 | margin: 2rem 0; | |
| 408 | border-radius: var(--curve-sm); | |
| 409 | } | |
| 410 | ||
| 367 | 411 | .license-content { |
| 368 | 412 | max-height: 500px; |
| 369 | 413 | overflow: scroll; |
| @@ -372,7 +416,7 @@ const licenseContent = async () => { | ||
| 372 | 416 | border-radius: var(--curve-sm); |
| 373 | 417 | padding: 0.5rem; |
| 374 | 418 | font-size: 0.7rem; |
| 375 | font-family: mono; | |
| 419 | font-family: 'Lekton', monospace; | |
| 376 | 420 | max-width: 100vw; |
| 377 | 421 | white-space: pre-line; |
| 378 | 422 | } |
web/src/pages/inventory/[...inventoryId].astro −2
| @@ -1,11 +1,9 @@ | ||
| 1 | 1 | --- |
| 2 | 2 | import Layout from '@layouts/Layout.astro'; |
| 3 | 3 | import SavedServices from '@components/things/SavedServices.svelte'; |
| 4 | import GetSharableLink from '@components/things/GetSharableLink.svelte'; | |
| 5 | 4 | |
| 6 | 5 | import { fetchData } from '@utils/fetch-data'; |
| 7 | 6 | import Button from '@components/form/Button.astro'; |
| 8 | import EditableTitle from '@components/form/EditableTitle.svelte'; | |
| 9 | 7 | import type { Category } from '../../types/Service'; |
| 10 | 8 | |
| 11 | 9 | const categories = (await fetchData())?.categories || ([] as Category[]); |
web/src/pages/search/[...searchTerm].astro +27 −19
| @@ -4,15 +4,14 @@ import Fuse from 'fuse.js'; | ||
| 4 | 4 | import Layout from '@layouts/Layout.astro'; |
| 5 | 5 | import { fetchData, slugify } from '@utils/fetch-data'; |
| 6 | 6 | import { prepareSearchItems, searchOptions } from '@utils/do-searchy-searchy'; |
| 7 | import type { SearchItem } from '@utils/do-searchy-searchy'; | |
| 7 | 8 | import Search from '@components/things/Search.svelte'; |
| 8 | 9 | import SmartSuggestions from '@components/things/SmartSuggestions.svelte'; |
| 9 | 10 | import FontAwesome from '@components/form/FontAwesome.svelte'; |
| 10 | 11 | |
| 11 | import type { Service } from '../../types/Service'; | |
| 12 | ||
| 13 | 12 | export const prerender = false; |
| 14 | 13 | |
| 15 | let fuse: Fuse<any>; | |
| 14 | let fuse: Fuse<SearchItem>; | |
| 16 | 15 | |
| 17 | 16 | const categories = (await fetchData())?.categories; |
| 18 | 17 | |
| @@ -28,26 +27,35 @@ const searchResults = fuse | ||
| 28 | 27 | |
| 29 | 28 | const services = searchResults.filter((result) => result.type === 'Service'); |
| 30 | 29 | |
| 30 | interface GroupedSection { | |
| 31 | sectionName: string; | |
| 32 | items: SearchItem[]; | |
| 33 | } | |
| 34 | ||
| 35 | interface GroupedCategory { | |
| 36 | categoryName: string; | |
| 37 | sections: Record<string, GroupedSection>; | |
| 38 | } | |
| 39 | ||
| 31 | 40 | const putResultsIntoGroups = () => { |
| 32 | const grouped = services.reduce((acc, item) => { | |
| 33 | const { category: categoryName, sectionName, ...service } = item; | |
| 41 | const grouped: Record<string, GroupedCategory> = {}; | |
| 34 | 42 | |
| 35 | if (!acc[categoryName]) { | |
| 36 | acc[categoryName] = { categoryName, sections: {} }; | |
| 37 | } | |
| 43 | for (const item of services) { | |
| 44 | const categoryName = item.category; | |
| 45 | const sectionName = item.sectionName || ''; | |
| 38 | 46 | |
| 39 | if (!acc[categoryName].sections[sectionName]) { | |
| 40 | acc[categoryName].sections[sectionName] = { sectionName, items: [] }; | |
| 47 | if (!grouped[categoryName]) { | |
| 48 | grouped[categoryName] = { categoryName, sections: {} }; | |
| 41 | 49 | } |
| 42 | 50 | |
| 43 | acc[categoryName].sections[sectionName].items.push(service); | |
| 51 | if (!grouped[categoryName].sections[sectionName]) { | |
| 52 | grouped[categoryName].sections[sectionName] = { sectionName, items: [] }; | |
| 53 | } | |
| 44 | 54 | |
| 45 | return acc; | |
| 46 | }, {}); | |
| 55 | grouped[categoryName].sections[sectionName].items.push(item); | |
| 56 | } | |
| 47 | 57 | |
| 48 | // Convert the grouped object into the desired array structure. | |
| 49 | // And fuck it, let's use `any` | |
| 50 | return Object.values(grouped).map((category: any) => ({ | |
| 58 | return Object.values(grouped).map((category) => ({ | |
| 51 | 59 | categoryName: category.categoryName, |
| 52 | 60 | sections: Object.values(category.sections), |
| 53 | 61 | })); |
| @@ -74,7 +82,7 @@ const beer = putResultsIntoGroups(); | ||
| 74 | 82 | </section> |
| 75 | 83 | <div class="results"> |
| 76 | 84 | { |
| 77 | beer.map((category: any) => ( | |
| 85 | beer.map((category) => ( | |
| 78 | 86 | <div class="category"> |
| 79 | 87 | <a class="category-title" href={`/${slugify(category.categoryName)}`}> |
| 80 | 88 | <h3>{category.categoryName}</h3> |
| @@ -83,11 +91,11 @@ const beer = putResultsIntoGroups(); | ||
| 83 | 91 | <FontAwesome iconName={slugify(category.categoryName)} /> |
| 84 | 92 | </span> |
| 85 | 93 | <ul class="section-list"> |
| 86 | {category.sections.map((section: any) => ( | |
| 94 | {category.sections.map((section) => ( | |
| 87 | 95 | <li class="section-item"> |
| 88 | 96 | <h4>{section.sectionName}</h4> |
| 89 | 97 | <ul class="service-list"> |
| 90 | {section.items.map((item: Service) => ( | |
| 98 | {section.items.map((item) => ( | |
| 91 | 99 | <li> |
| 92 | 100 | <a href={item.url}>{item.name}</a> |
| 93 | 101 | </li> |
web/src/utils/do-searchy-searchy.test.ts +5 −4
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | import { describe, it, expect } from 'vitest'; |
| 2 | 2 | import { prepareSearchItems } from './do-searchy-searchy'; |
| 3 | import type { SearchItem } from './do-searchy-searchy'; | |
| 3 | 4 | import type { Category } from '../types/Service'; |
| 4 | 5 | |
| 5 | 6 | const makeCategory = (overrides: Partial<Category> = {}): Category => |
| @@ -35,7 +36,7 @@ describe('prepareSearchItems', () => { | ||
| 35 | 36 | }), |
| 36 | 37 | ] as Category[]; |
| 37 | 38 | const items = prepareSearchItems(categories); |
| 38 | const section = items.find((i: { type: string }) => i.type === 'Section'); | |
| 39 | const section = items.find((i: SearchItem) => i.type === 'Section'); | |
| 39 | 40 | expect(section).toMatchObject({ |
| 40 | 41 | type: 'Section', |
| 41 | 42 | sectionName: 'Messaging', |
| @@ -66,7 +67,7 @@ describe('prepareSearchItems', () => { | ||
| 66 | 67 | }), |
| 67 | 68 | ] as Category[]; |
| 68 | 69 | const items = prepareSearchItems(categories); |
| 69 | const service = items.find((i: { type: string }) => i.type === 'Service'); | |
| 70 | const service = items.find((i: SearchItem) => i.type === 'Service'); | |
| 70 | 71 | expect(service).toMatchObject({ |
| 71 | 72 | type: 'Service', |
| 72 | 73 | name: 'Signal', |
| @@ -99,7 +100,7 @@ describe('prepareSearchItems', () => { | ||
| 99 | 100 | }), |
| 100 | 101 | ] as Category[]; |
| 101 | 102 | const items = prepareSearchItems(categories); |
| 102 | const cat = items.find((i: { type: string }) => i.type === 'Category'); | |
| 103 | expect(cat.itemCount).toBe(3); | |
| 103 | const cat = items.find((i: SearchItem) => i.type === 'Category'); | |
| 104 | expect(cat?.itemCount).toBe(3); | |
| 104 | 105 | }); |
| 105 | 106 | }); |
web/src/utils/do-searchy-searchy.ts +14 −2
| @@ -1,7 +1,19 @@ | ||
| 1 | 1 | import type { Category } from '../types/Service'; |
| 2 | 2 | |
| 3 | export const prepareSearchItems = (categories: Category[]) => { | |
| 4 | const items: any = []; | |
| 3 | export interface SearchItem { | |
| 4 | type: 'Category' | 'Section' | 'Service'; | |
| 5 | category: string; | |
| 6 | itemCount?: number; | |
| 7 | sectionName?: string; | |
| 8 | description?: string; | |
| 9 | name?: string; | |
| 10 | url?: string; | |
| 11 | github?: string; | |
| 12 | logo?: string; | |
| 13 | } | |
| 14 | ||
| 15 | export const prepareSearchItems = (categories: Category[]): SearchItem[] => { | |
| 16 | const items: SearchItem[] = []; | |
| 5 | 17 | // Add each category |
| 6 | 18 | categories.forEach((category) => { |
| 7 | 19 | items.push({ |
web/src/utils/fetch-website-info.ts +1 −1
| @@ -61,7 +61,7 @@ interface Redirection { | ||
| 61 | 61 | found: boolean; |
| 62 | 62 | external: boolean; |
| 63 | 63 | url: string; |
| 64 | redirects: any[]; | |
| 64 | redirects: string[]; | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | interface ResponseHeaders { |