web/src/components/things/ListingHero.astro

383 lines · 8410 bytes

  1---
  2import type { Section, Service } from '../../types/Service';
  3import { slugify } from '@utils/fetch-data';
  4import { parseMarkdown, formatLink, codebergUrl } from '@utils/parse-markdown';
  5import FontAwesome from '@components/form/FontAwesome.svelte';
  6import SaveListing from '@components/things/SaveListing.svelte';
  7import ServiceIcon from '@components/things/ServiceIcon.astro';
  8
  9interface Props {
 10	service: Service;
 11	parentSection: Section;
 12	categoryName: string;
 13	privacyPolicyLink: string | null;
 14}
 15
 16const { service, parentSection, categoryName, privacyPolicyLink } = Astro.props;
 17const {
 18	name,
 19	description,
 20	url,
 21	github,
 22	codeberg,
 23	git,
 24	tosdrId,
 25	iosApp,
 26	androidApp,
 27	discordInvite,
 28	subreddit,
 29	icon,
 30	followWith,
 31	links,
 32	securityAudited,
 33	openSource,
 34	acceptsCrypto,
 35} = service;
 36
 37const catSlug = slugify(categoryName);
 38const secSlug = slugify(parentSection.name);
 39
 40const otherServices = parentSection.services.filter(
 41	(s: Service) => s.name !== name,
 42);
 43
 44const infoLinks = [
 45	url && { label: 'Homepage', href: url, text: formatLink(url) },
 46	github && {
 47		label: 'GitHub',
 48		href: `https://github.com/${github}`,
 49		text: `github.com/${github}`,
 50	},
 51	codeberg && {
 52		label: 'Codeberg',
 53		href: codebergUrl(codeberg),
 54		text: formatLink(codebergUrl(codeberg)),
 55	},
 56	git && {
 57		label: 'Source',
 58		href: git,
 59		text: formatLink(git),
 60	},
 61	tosdrId && {
 62		label: 'Privacy',
 63		href: privacyPolicyLink,
 64		text: formatLink(privacyPolicyLink || ''),
 65	},
 66	iosApp && { label: 'iOS App', href: iosApp, text: formatLink(iosApp) },
 67	androidApp && {
 68		label: 'Android App',
 69		href: `https://play.google.com/store/apps/details?id=${androidApp}`,
 70		text: `play.google.com/.../${androidApp}`,
 71	},
 72	discordInvite && {
 73		label: 'Discord',
 74		href: `https://discord.com/invite/${discordInvite}`,
 75		text: discordInvite,
 76	},
 77	subreddit && {
 78		label: 'Subreddit',
 79		href: `https://reddit.com/r/${subreddit}`,
 80		text: `r/${subreddit}`,
 81	},
 82	url && {
 83		label: 'Web info',
 84		href: `https://web-check.xyz/check/${formatLink(url)}`,
 85		text: `web-check.xyz/check/${formatLink(url).split('/')[0]}`,
 86	},
 87	...(links || []).map((link) => ({
 88		label: link.title,
 89		href: link.url,
 90		text: link.url,
 91	})),
 92].filter(Boolean) as { label: string; href: string | null; text: string }[];
 93
 94const highlights = [
 95	securityAudited && {
 96		icon: 'securityAudited',
 97		text: 'Security Audited',
 98		cls: 'great',
 99		title: `${name} has been security audited by an accredited auditor, with results published publicly`,
100	},
101	acceptsCrypto && {
102		icon: 'cryptoAccepted',
103		text: 'Crypto Payments Accepted',
104		cls: 'great',
105		title: `${name} accepts anonymous payment methods`,
106	},
107	securityAudited === false && {
108		icon: 'notSecurityAudited',
109		text: 'No Security Audit',
110		cls: 'warning',
111		title: `${name} has not been audited`,
112	},
113	openSource === false && {
114		icon: 'closedSource',
115		text: 'Not Open Source',
116		cls: 'warning',
117		title: `${name} is not open source`,
118	},
119	(openSource || ((github || codeberg || git) && openSource !== false)) && {
120		icon: 'openSource',
121		text: 'Open Source',
122		cls: 'great',
123		title: `${name} is open source`,
124	},
125].filter(Boolean) as {
126	icon: string;
127	text: string;
128	cls: string;
129	title: string;
130}[];
131---
132
133<section class="hero-section">
134	<div class="service-head">
135		<h1>{name}</h1>
136		<span class="url-wrap">
137			<a class="service-url" href={url}>{formatLink(url)}</a>
138			<span class="follow-with">{followWith}</span>
139		</span>
140	</div>
141	<div class="breadcrumbs">
142		<span>
143			<a href="/">Awesome Privacy</a>
144			➔ <a href={`/${catSlug}/`}>{categoryName}</a>
145			➔ <a href={`/${catSlug}/${secSlug}/`}>{parentSection.name}</a>
146			➔ <a href={`/${catSlug}/${secSlug}/${slugify(name)}/`}>{name}</a>
147		</span>
148	</div>
149	<div class="save-listing">
150		<SaveListing
151			client:visible
152			categoryName={categoryName}
153			sectionName={parentSection.name}
154			serviceName={name}
155			showLabel={true}
156		/>
157	</div>
158	<div class="intro">
159		<ServiceIcon name={name} url={url} icon={icon} size={60} eager />
160		<div>
161			<p class="description" set:html={parseMarkdown(description)} />
162			<ul>
163				{
164					infoLinks.map((link) => (
165						<li>
166							<b>{link.label}:</b>
167							<a href={link.href} target="_blank" rel="noopener noreferrer">
168								{link.text}
169							</a>
170						</li>
171					))
172				}
173			</ul>
174			<div class="related">
175				{
176					(parentSection.alternativeTo || []).length > 0 && (
177						<div class="related-group">
178							<h2 class="avoid">
179								<FontAwesome iconName="faceBad" /> Avoid
180							</h2>
181							<ul>
182								{(parentSection.alternativeTo || []).map((alt: string) => (
183									<li>
184										<span>{alt}</span>
185									</li>
186								))}
187							</ul>
188						</div>
189					)
190				}
191				{
192					otherServices.length > 0 && (
193						<div class="related-group">
194							<h2 class="consider">
195								<FontAwesome iconName="faceGood" /> Also Consider
196							</h2>
197							<ul>
198								{otherServices.map((s: Service) => (
199									<li>
200										<a href={`/${catSlug}/${secSlug}/${slugify(s.name)}/`}>
201											{s.name}
202										</a>
203									</li>
204								))}
205							</ul>
206						</div>
207					)
208				}
209			</div>
210		</div>
211	</div>
212	<div class="highlights">
213		{
214			highlights.map((h) => (
215				<span class={`meta-item ${h.cls}`} title={h.title}>
216					<FontAwesome iconName={h.icon} /> {h.text}
217				</span>
218			))
219		}
220	</div>
221</section>
222
223<style lang="scss">
224	.hero-section {
225		margin: var(--space-md) 0 var(--space-2xl) 0;
226		padding: var(--space-md);
227		min-height: 8rem;
228		position: relative;
229		border: var(--border-heavy);
230		box-shadow: var(--shadow-lg);
231		background: var(--surface);
232	}
233
234	.service-head {
235		h1 {
236			font-size: var(--text-4xl);
237			margin: 0;
238			@media (max-width: 768px) {
239				text-align: center;
240			}
241		}
242		.url-wrap {
243			display: flex;
244			align-items: center;
245			gap: var(--space-sm);
246			a {
247				font-size: var(--text-md);
248			}
249			.follow-with {
250				font-style: italic;
251				opacity: var(--opacity-muted);
252			}
253			@media (max-width: 768px) {
254				flex-direction: column;
255			}
256		}
257	}
258
259	.save-listing {
260		position: absolute;
261		top: var(--space-xl);
262		right: var(--space-md);
263	}
264
265	.intro {
266		font-size: var(--text-md);
267		font-style: italic;
268		opacity: 0.9;
269		display: flex;
270		gap: var(--space-sm);
271		@media (max-width: 768px) {
272			flex-direction: column;
273		}
274		:global(.service-icon-wrap) {
275			border-radius: var(--curve-md);
276			margin-top: var(--space-md);
277			@media (max-width: 768px) {
278				margin: var(--space-md) auto 0 auto;
279			}
280		}
281		ul {
282			padding-left: var(--space-md);
283			list-style: circle;
284			font-style: normal;
285			font-size: var(--text-base);
286			margin-top: 0;
287			b {
288				font-size: var(--text-base);
289				font-weight: 400;
290				min-width: 100px;
291				display: inline-block;
292				@media (max-width: 768px) {
293					width: auto;
294					display: block;
295				}
296			}
297		}
298	}
299
300	.related {
301		display: flex;
302		gap: var(--space-lg);
303		flex-wrap: wrap;
304		margin: var(--space-md) 0;
305		.related-group {
306			h2 {
307				font-size: var(--text-sm);
308				font-family: var(--font-subtitle);
309				text-transform: uppercase;
310				opacity: var(--opacity-muted);
311				margin: 0 0 var(--space-xs) 0;
312				display: flex;
313				align-items: center;
314				gap: var(--space-xs);
315				:global(svg) {
316					width: var(--text-sm);
317					height: var(--text-sm);
318				}
319				&.avoid :global(svg) {
320					color: var(--danger);
321				}
322				&.consider :global(svg) {
323					color: var(--success-muted);
324				}
325			}
326			ul {
327				list-style: none;
328				padding: 0;
329				margin: 0;
330				display: flex;
331				flex-wrap: wrap;
332				gap: var(--space-xs);
333				li {
334					font-size: var(--text-sm);
335					padding: var(--space-xs) var(--space-sm);
336					border: var(--border-light);
337					border-radius: var(--curve-pill);
338					a {
339						color: var(--foreground);
340						text-decoration: none;
341						&:hover {
342							color: var(--accent-text);
343						}
344					}
345					span {
346						opacity: var(--opacity-soft);
347					}
348				}
349			}
350		}
351	}
352
353	.highlights {
354		display: flex;
355		gap: var(--space-md);
356		flex-wrap: wrap;
357		align-items: center;
358		justify-content: end;
359		.meta-item {
360			display: flex;
361			align-items: center;
362			gap: var(--space-xs);
363			font-size: var(--text-sm);
364			padding: var(--space-sm) 0;
365			:global(svg) {
366				width: var(--text-md);
367				height: var(--text-md);
368			}
369		}
370		.warning {
371			color: var(--danger);
372			:global(svg) {
373				color: var(--danger);
374			}
375		}
376		.great {
377			color: var(--success-muted);
378			:global(svg) {
379				color: var(--success-muted);
380			}
381		}
382	}
383</style>