web/src/pages/all.astro

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