web/src/layouts/Layout.astro

413 lines · 9480 bytes

  1---
  2import { ClientRouter } from 'astro:transitions';
  3import NavBar from '@components/scafold/NavBar.astro';
  4import Footer from '@components/scafold/Footer.astro';
  5import config from '../site-config';
  6
  7interface Props {
  8	title?: string; // Page title
  9	description?: string; // Overide description tag
 10	keywords?: string; // Overide keywords tag
 11	hideNav?: boolean; // Don't show the navbar (just homepage)
 12	author?: string; // Author of the content
 13	customSchemaJson?: Record<string, unknown>; // Custom schema item
 14	breadcrumbs?: Array<{
 15		name: string;
 16		item: string;
 17	}>;
 18}
 19
 20const {
 21	title = config.title,
 22	description = config.description,
 23	keywords = config.keywords,
 24	author = config.author,
 25	hideNav = false,
 26	breadcrumbs,
 27	customSchemaJson,
 28} = Astro.props;
 29
 30// Crumbs arrive as '/', 'api' or 'category/section', so normalise to a canonical URL
 31const crumbUrl = (item: string) => {
 32	const path = item.replace(/^\/+|\/+$/g, '');
 33	return `https://awesome-privacy.xyz/${path && `${path}/`}`;
 34};
 35
 36// Always advertise the trailing-slash form, so server-rendered routes agree with the sitemap
 37const canonical = crumbUrl(Astro.url.pathname);
 38
 39const makeBreadcrumbs = () => {
 40	if (!breadcrumbs) return null;
 41	return {
 42		'@context': 'https://schema.org',
 43		'@type': 'BreadcrumbList',
 44		itemListElement: breadcrumbs.map((breadcrumb, index) => ({
 45			'@type': 'ListItem',
 46			position: index + 1,
 47			name: breadcrumb.name,
 48			item: crumbUrl(breadcrumb.item),
 49		})),
 50	};
 51};
 52
 53const makeSearchLd = () => {
 54	return {
 55		'@context': 'https://schema.org',
 56		'@type': 'WebSite',
 57		name: 'Awesome Privacy',
 58		url: 'https://awesome-privacy.xyz/',
 59		potentialAction: [
 60			{
 61				'@type': 'SearchAction',
 62				target: {
 63					'@type': 'EntryPoint',
 64					urlTemplate:
 65						'https://awesome-privacy.xyz/search/{search_term_string}/',
 66				},
 67				'query-input': 'required name=search_term_string',
 68			},
 69		],
 70	};
 71};
 72---
 73
 74<!doctype html>
 75<html lang="en" data-theme="dark">
 76	<head>
 77		<script is:inline>
 78			const setTheme = () => {
 79				const stored = localStorage.getItem('theme');
 80				const prefersLight = matchMedia(
 81					'(prefers-color-scheme: light)',
 82				).matches;
 83				document.documentElement.dataset.theme =
 84					stored || (prefersLight ? 'light' : 'dark');
 85			};
 86			setTheme();
 87			document.addEventListener('astro:after-swap', setTheme);
 88		</script>
 89		<ClientRouter />
 90
 91		<!-- Core info -->
 92		<title>{title}</title>
 93		<meta name="description" content={description} />
 94		<meta name="keywords" content={keywords} />
 95		<meta name="author" content={author} />
 96
 97		<!-- Page info, viewport, Astro credit -->
 98		<meta charset="UTF-8" />
 99		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
100		<meta
101			name="generator"
102			content={`Built by an actual human, in Astro. ${Astro.generator}`}
103		/>
104		<meta name="robots" content="index, follow" />
105		<link rel="canonical" href={canonical} />
106		<link
107			rel="alternate"
108			type="application/rss+xml"
109			title="Awesome Privacy — Changelog"
110			href="/rss.xml"
111		/>
112
113		<!-- Preload critical fonts -->
114		<link
115			rel="preload"
116			as="font"
117			href="/fonts/Rubik/Rubik-Regular.woff2"
118			type="font/woff2"
119			crossorigin
120		/>
121		<link
122			rel="preload"
123			as="font"
124			href="/fonts/Lekton/Lekton-Bold.woff2"
125			type="font/woff2"
126			crossorigin
127		/>
128
129		<!-- Icons and colors -->
130		<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
131		<link rel="icon" type="image/png" sizes="64x64" href="/favicon.png" />
132		<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
133
134		<!-- Social media meta tags (Open Graphh + Twitter) -->
135		<meta property="og:site_name" content="Awesome Privacy" />
136		<meta property="og:type" content="website" />
137		<meta property="og:url" content={canonical} />
138		<meta property="og:title" content={title} />
139		<meta property="og:description" content={description} />
140		<meta
141			property="og:image"
142			content="https://awesome-privacy.xyz/banner.png"
143		/>
144		<meta name="twitter:card" content="summary_large_image" />
145		<meta name="twitter:url" content={canonical} />
146		<meta name="twitter:title" content={title} />
147		<meta name="twitter:description" content={description} />
148		<meta
149			name="twitter:image"
150			content="https://awesome-privacy.xyz/banner.png"
151		/>
152		<link
153			rel="twitter:image"
154			sizes="180x180"
155			href="https://awesome-privacy.xyz/apple-touch-icon.png"
156		/>
157		<meta name="twitter:site" content="@Lissy_Sykes" />
158		<meta name="twitter:creator" content="@Lissy_Sykes" />
159
160		<!-- Non-tracking hit counter -->
161		<script
162			defer
163			is:inline
164			type="text/partytown"
165			data-domain="awesome-privacy.xyz"
166			src="https://no-track.as93.net/js/script.js"></script>
167
168		<!-- Schema.org markup for Google -->
169		{
170			breadcrumbs && (
171				<script
172					is:inline
173					type="application/ld+json"
174					set:html={JSON.stringify(makeBreadcrumbs())}
175				/>
176			)
177		}
178		{
179			customSchemaJson && (
180				<script
181					is:inline
182					type="application/ld+json"
183					set:html={JSON.stringify(customSchemaJson)}
184				/>
185			)
186		}
187		<script
188			is:inline
189			type="application/ld+json"
190			set:html={JSON.stringify(makeSearchLd())}
191		/>
192	</head>
193	<body>
194		<a href="#main-content" class="skip-link">Skip to content</a>
195		{!hideNav && <NavBar />}
196		<div id="main-content">
197			<slot />
198		</div>
199		<Footer />
200	</body>
201</html>
202
203<style is:global>
204	@import '../styles/values.css';
205	@import '../styles/typography.css';
206</style>
207
208<style is:global lang="scss">
209	html {
210		::selection {
211			background: var(--accent);
212			color: var(--accent-fg);
213		}
214		scroll-behavior: smooth;
215	}
216	body {
217		margin: 0;
218		min-height: 100dvh;
219		display: flex;
220		flex-direction: column;
221		color: var(--foreground);
222		background: var(--background);
223	}
224	#main-content {
225		flex: 1;
226	}
227
228	:focus-visible {
229		outline: 2px solid var(--accent-text);
230		outline-offset: 2px;
231	}
232
233	.skip-link {
234		position: absolute;
235		left: var(--space-sm);
236		top: calc(var(--space-sm) * -10);
237		z-index: 200;
238		padding: var(--space-sm) var(--space-md);
239		font-family: var(--font-subtitle);
240		font-weight: bold;
241		color: var(--accent-fg);
242		background: var(--accent);
243		border: var(--border-heavy);
244		box-shadow: var(--shadow-sm);
245		transition: top 0.2s ease-in-out;
246		&:focus {
247			top: var(--space-sm);
248		}
249	}
250
251	/* Drop movement, keep colour/depth feedback so states stay legible */
252	@media (prefers-reduced-motion: reduce) {
253		html {
254			scroll-behavior: auto;
255		}
256		*,
257		::before,
258		::after {
259			animation-duration: 0.01ms !important;
260			animation-iteration-count: 1 !important;
261			transition-property:
262				color, background-color, border-color, box-shadow, opacity !important;
263		}
264	}
265
266	.pagination-navigation {
267		display: flex;
268		justify-content: space-between;
269		align-items: center;
270		padding: var(--space-md) 0;
271		.button {
272			min-width: 120px;
273			width: fit-content;
274			padding: var(--space-xs) var(--space-md);
275			text-align: right;
276			&:first-child {
277				text-align: left;
278			}
279			p {
280				margin: 0;
281				font-weight: normal;
282				font-size: var(--text-base);
283			}
284			span {
285				font-size: var(--text-sm);
286			}
287		}
288		.nothing {
289			width: 120px;
290		}
291		.go-to-category {
292			color: var(--foreground);
293			font-size: var(--text-sm);
294			opacity: var(--opacity-dim);
295			@media (max-width: 768px) {
296				display: none;
297			}
298		}
299	}
300
301	.breadcrumbs {
302		opacity: var(--opacity-dim);
303		font-size: var(--text-sm);
304		position: absolute;
305		right: var(--space-md);
306		top: var(--space-md);
307		a {
308			color: var(--foreground);
309			transition: var(--transition-fast);
310			&:hover {
311				color: var(--accent-text);
312			}
313		}
314		@media (max-width: 768px) {
315			display: none;
316		}
317	}
318
319	.sr-only {
320		position: absolute;
321		width: 1px;
322		height: 1px;
323		padding: 0;
324		margin: -1px;
325		overflow: hidden;
326		clip-path: inset(50%);
327		white-space: nowrap;
328		border: 0;
329	}
330
331	.page-title {
332		font-family: var(--font-subtitle);
333		font-size: var(--text-4xl);
334		color: var(--accent-3-text);
335		margin: var(--space-lg) 0 var(--space-md);
336		text-align: center;
337	}
338
339	.small-button {
340		display: inline-block;
341		font-family: var(--font-subtitle);
342		font-size: var(--text-sm);
343		font-weight: bold;
344		text-decoration: none;
345		color: var(--accent-fg);
346		background: var(--accent);
347		border: var(--border-light);
348		box-shadow: var(--shadow-sm);
349		padding: var(--space-xs) var(--space-md);
350		transition: var(--transition-normal);
351		&:hover {
352			box-shadow: var(--shadow-sm-hover);
353		}
354	}
355
356	.accent-heading {
357		font-size: var(--text-3xl);
358		margin: calc(var(--space-lg) * -1) 0 var(--space-md)
359			calc(var(--space-lg) * -1);
360		box-shadow: var(--shadow-lg);
361		background: var(--accent);
362		color: var(--accent-fg);
363		width: fit-content;
364		padding: var(--space-xs) var(--space-sm);
365		@media (max-width: 768px) {
366			margin: calc(var(--space-lg) * -1) auto var(--space-lg) auto;
367		}
368	}
369
370	.further-info,
371	.notable-mentions,
372	.word-of-warning,
373	.submit-alternative {
374		h2,
375		h3 {
376			font-size: var(--text-lg);
377			margin: var(--space-md) 0;
378		}
379		p {
380			font-size: var(--text-sm);
381			opacity: var(--opacity-soft);
382			strong {
383				font-weight: 500;
384			}
385			a {
386				color: var(--foreground);
387				transition: var(--transition-fast);
388				&:hover {
389					color: var(--accent-text);
390				}
391			}
392		}
393		strong {
394			font-weight: 500;
395		}
396		h4 {
397			font-size: var(--text-md);
398			margin: var(--space-sm) 0 0 0;
399		}
400		ul {
401			list-style: circle;
402			padding-left: var(--space-md);
403			font-size: var(--text-sm);
404			opacity: var(--opacity-soft);
405			li {
406				margin-bottom: var(--space-xs);
407				p {
408					display: inline;
409				}
410			}
411		}
412	}
413</style>