web/src/pages/all.astro

303 lines · 8155 bytes

  1---
  2import Layout from '@layouts/Layout.astro';
  3import ServiceCard from '@components/things/ServiceCard.astro';
  4import type { AwesomePrivacy, Section, Service } from '../types/Service';
  5import { fetchData, slugify } from '@utils/fetch-data';
  6import FontAwesome from '@components/form/FontAwesome.svelte';
  7
  8const categories = (await fetchData() as AwesomePrivacy)?.categories || [];
  9---
 10
 11<Layout
 12	title="All Services | Awesome Privacy"
 13	description="Browse every privacy-respecting service and app listed on Awesome Privacy, organised by category and section."
 14>
 15	<div class="page">
 16		<aside class="sidebar" aria-label="Table of contents">
 17			<button
 18				class="toc-toggle"
 19				type="button"
 20				aria-expanded="false"
 21				aria-controls="toc"
 22			>Contents</button>
 23			<nav id="toc" class="toc">
 24				<div class="toc-inner">
 25					{categories.map((category) => (
 26						<details open>
 27							<summary>{category.name}</summary>
 28							<ul>
 29								<li>
 30									<a href={`#${slugify(category.name)}`}>{category.name} (all)</a>
 31								</li>
 32								{category.sections.map((section: Section) => (
 33									<li>
 34										<a href={`#${slugify(category.name)}-${slugify(section.name)}`}>
 35											{section.name}
 36										</a>
 37									</li>
 38								))}
 39							</ul>
 40						</details>
 41					))}
 42				</div>
 43			</nav>
 44		</aside>
 45
 46		<main>
 47			<h1 class="page-title">All Listings</h1>
 48			{categories.map((category) => (
 49				<Fragment>
 50				<h2 id={slugify(category.name)}>
 51					<FontAwesome iconName={slugify(category.name)} />
 52					<a href={`/${slugify(category.name)}/`}>{category.name}</a>
 53				</h2>
 54				<article>
 55					{category.sections.map((section: Section) => (
 56						<Fragment>
 57							<h3 id={`${slugify(category.name)}-${slugify(section.name)}`}>
 58								<a href={`/${slugify(category.name)}/${slugify(section.name)}/`}>
 59									{section.name}
 60								</a>
 61							</h3>
 62							<section class="grid">
 63								{[...section.services].sort((a, b) => a.name.localeCompare(b.name)).map((service: Service) => (
 64									<ServiceCard
 65										service={service}
 66										sectionName={section.name}
 67										categoryName={category.name}
 68									/>
 69								))}
 70							</section>
 71							{section.services.length === 0 && (
 72								<div class="nothing-yet">
 73									<p>
 74										<strong>This section is still a work in progress</strong><br />
 75										Check back soon, or help us complete it by submitting a
 76										<a href="https://github.com/lissy93/awesome-privacy">pull request</a>
 77										or <a href="/submit/">entry</a>.
 78									</p>
 79								</div>
 80							)}
 81						</Fragment>
 82					))}
 83				</article>
 84				</Fragment>
 85			))}
 86		</main>
 87	</div>
 88</Layout>
 89
 90<script>
 91	document.addEventListener('astro:page-load', () => {
 92		const links = document.querySelectorAll<HTMLAnchorElement>('.toc a');
 93		const headings = document.querySelectorAll<HTMLElement>('h2[id], h3[id]');
 94		const toggle = document.querySelector('.toc-toggle');
 95		const toc = document.querySelector('.toc');
 96
 97		// Scroll-spy: highlight active TOC link
 98		const linkMap = new Map<string, HTMLAnchorElement>();
 99		links.forEach((link) => {
100			const id = link.getAttribute('href')?.slice(1);
101			if (id) linkMap.set(id, link);
102		});
103
104		let active: HTMLAnchorElement | null = null;
105
106		const observer = new IntersectionObserver((entries) => {
107			entries.forEach((entry) => {
108				if (entry.isIntersecting) {
109					active?.classList.remove('active');
110					const link = linkMap.get(entry.target.id);
111					if (link) {
112						link.classList.add('active');
113						link.closest('details')?.setAttribute('open', '');
114						active = link;
115					}
116				}
117			});
118		}, { rootMargin: '0px 0px -70% 0px' });
119
120		headings.forEach((h) => observer.observe(h));
121
122		// Mobile TOC toggle
123		const onToggle = () => {
124			const isOpen = toc?.classList.toggle('open');
125			toggle?.setAttribute('aria-expanded', String(!!isOpen));
126		};
127		toggle?.addEventListener('click', onToggle);
128
129		// Close mobile TOC on link click
130		const onLinkClick = () => {
131			toc?.classList.remove('open');
132			toggle?.setAttribute('aria-expanded', 'false');
133		};
134		links.forEach((link) => link.addEventListener('click', onLinkClick));
135
136		// Cleanup on page transition
137		document.addEventListener('astro:before-swap', () => {
138			observer.disconnect();
139			toggle?.removeEventListener('click', onToggle);
140			links.forEach((link) => link.removeEventListener('click', onLinkClick));
141		}, { once: true });
142	});
143</script>
144
145<style lang="scss">
146	.page {
147		display: flex;
148		gap: var(--space-lg);
149		max-width: calc(100vw - 4rem);
150		margin: 0 auto;
151		padding: var(--space-md);
152	}
153
154	.sidebar {
155		position: sticky;
156		top: var(--space-md);
157		align-self: flex-start;
158		width: 260px;
159		flex-shrink: 0;
160		max-height: calc(100vh - var(--space-lg));
161		overflow-y: auto;
162
163		.toc-toggle {
164			display: none;
165			width: 100%;
166			padding: var(--space-sm) var(--space-md);
167			background: var(--accent-3);
168			color: var(--accent-3-fg);
169			font-family: var(--font-subtitle);
170			font-size: var(--text-md);
171			font-weight: bold;
172			border: var(--border-heavy);
173			box-shadow: var(--shadow-sm);
174			cursor: pointer;
175			&:hover { box-shadow: var(--shadow-sm-hover); }
176		}
177
178		.toc {
179			details {
180				summary {
181					display: flex;
182					align-items: center;
183					font-weight: bold;
184					font-family: var(--font-subtitle);
185					font-size: var(--text-base);
186					padding: var(--space-xs) 0;
187					cursor: pointer;
188					list-style: none;
189					color: var(--foreground);
190					opacity: var(--opacity-subtle);
191					&::marker, &::-webkit-details-marker { display: none; }
192					&::before {
193						content: '▸';
194						margin-right: var(--space-xs);
195						transition: var(--transition-fast);
196					}
197				}
198				&[open] > summary::before { transform: rotate(90deg); }
199			}
200			ul {
201				list-style: none;
202				padding-left: var(--space-md);
203				margin: 0 0 var(--space-xs) 0;
204			}
205			a {
206				color: var(--foreground);
207				text-decoration: none;
208				font-size: var(--text-sm);
209				opacity: var(--opacity-soft);
210				transition: var(--transition-fast);
211				display: block;
212				padding: var(--space-xs) 0;
213				&:hover { color: var(--accent-text); opacity: 1; }
214				&.active { color: var(--accent-text); opacity: 1; font-weight: bold; }
215			}
216		}
217	}
218
219	main {
220		flex: 1;
221		min-width: 0;
222
223		h2, h3 { scroll-margin-top: var(--space-lg); }
224
225		h2 {
226			margin: var(--space-lg) auto 0 auto;
227			font-size: var(--text-4xl);
228			text-align: center;
229			opacity: var(--opacity-muted);
230			display: flex;
231			justify-content: center;
232			align-items: center;
233			gap: var(--space-md);
234			a { color: var(--accent-3-text); text-decoration: none; }
235			:global(svg) {
236				width: var(--text-4xl);
237				height: var(--text-4xl);
238				color: var(--accent-3-text);
239			}
240		}
241
242		h3 {
243			font-size: var(--text-3xl);
244			margin: var(--space-lg) 0 var(--space-md) 0;
245			box-shadow: var(--shadow-lg);
246			background: var(--accent);
247			color: var(--accent-fg);
248			width: fit-content;
249			padding: var(--space-xs) var(--space-sm);
250			a {
251				color: var(--accent-fg);
252				font-family: var(--font-subtitle);
253				text-decoration: none;
254			}
255		}
256
257		.grid {
258			display: grid;
259			grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
260			gap: var(--space-md);
261		}
262
263		.nothing-yet {
264			background: var(--surface);
265			border: var(--border-heavy);
266			box-shadow: var(--shadow-lg);
267			border-radius: var(--curve-sm);
268			p {
269				font-size: var(--text-md);
270				opacity: var(--opacity-subtle);
271				font-style: italic;
272				text-align: center;
273				margin: var(--space-2xl) auto;
274				a { color: var(--accent-text); }
275			}
276		}
277	}
278
279	@media (max-width: 768px) {
280		.page { flex-direction: column; }
281		.sidebar {
282			position: static;
283			width: 100%;
284			max-height: none;
285			overflow: visible;
286			border: var(--border-heavy);
287			box-shadow: var(--shadow-lg);
288			background: var(--surface);
289			border-radius: var(--curve-sm);
290
291			.toc-toggle { display: block; }
292			.toc {
293				display: grid;
294				grid-template-rows: 0fr;
295				transition: grid-template-rows 0.3s ease;
296				.toc-inner { overflow: hidden; padding: 0 var(--space-sm); }
297				&.open { grid-template-rows: 1fr; }
298			}
299		}
300		main h2 { font-size: var(--text-3xl); }
301		main h3 { font-size: var(--text-2xl); }
302	}
303</style>