eratic / packages / core / src / components / BaseHead.astro
460 words
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
---
/**
 * Everything inside <head>.
 *
 * Note what is absent: no analytics, no tag manager, no font CDN, no
 * preconnect to a third party, no social pixel. A page from this site makes
 * requests to exactly one origin — its own. That is the whole privacy posture,
 * and it is enforced by the Content-Security-Policy Caddy sends (see
 * deploy/Caddyfile.eratic), so adding a third-party script would visibly break
 * rather than quietly start tracking people.
 */
import { IDENTITY, SITES, type SiteKey } from '../config.js';
import '../styles/fonts.css';
import '../styles/tokens.css';
import '../styles/base.css';
// Scoped entirely under .prose, so loading it on listing pages costs a couple
// of hundred bytes and nothing else. Importing it per-layout instead was the
// version that shipped articles in the interface sans with no paragraph
// spacing, because the one place it was missing was the one place it mattered.
import '../styles/prose.css';

interface Props {
	site: SiteKey;
	/** Page title. The site name is appended unless this is the home page. */
	title?: string;
	description?: string;
	/** Path of this page, used for the canonical URL. */
	path?: string;
	/** Absolute or root-relative image for link previews. */
	image?: string;
	/** "article" for individual entries, "website" for listings. */
	type?: 'website' | 'article';
	publishedTime?: Date;
	modifiedTime?: Date;
}

const {
	site,
	title,
	description,
	path = '/',
	image,
	type = 'website',
	publishedTime,
	modifiedTime,
} = Astro.props;

const def = SITES[site];
const pageTitle = title && title !== def.title ? `${title} · ${def.title}` : def.title;
const pageDescription = description ?? def.description;
const canonical = new URL(path, def.url).href;
const previewImage = image ? new URL(image, def.url).href : undefined;
---

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>{pageTitle}</title>
<meta name="description" content={pageDescription} />
<link rel="canonical" href={canonical} />

{/* Tells the browser both themes are supported before any CSS parses, so the
    very first paint is already the right colour instead of flashing white. */}
<meta name="color-scheme" content="light dark" />
<meta name="theme-color" content="#faf9f7" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#141619" media="(prefers-color-scheme: dark)" />

<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />

{
	def.feeds && (
		<>
			<link
				rel="alternate"
				type="application/rss+xml"
				title={`${def.title} · RSS`}
				href={new URL('/rss.xml', def.url).href}
			/>
			<link
				rel="alternate"
				type="application/feed+json"
				title={`${def.title} · JSON Feed`}
				href={new URL('/feed.json', def.url).href}
			/>
		</>
	)
}

{/* Open Graph. Plain markup — nothing is fetched from a social network. */}
<meta property="og:type" content={type} />
<meta property="og:title" content={pageTitle} />
<meta property="og:description" content={pageDescription} />
<meta property="og:url" content={canonical} />
<meta property="og:site_name" content={def.title} />
<meta property="og:locale" content={IDENTITY.locale} />
{previewImage && <meta property="og:image" content={previewImage} />}
{publishedTime && <meta property="article:published_time" content={publishedTime.toISOString()} />}
{modifiedTime && <meta property="article:modified_time" content={modifiedTime.toISOString()} />}

<meta name="twitter:card" content={previewImage ? 'summary_large_image' : 'summary'} />

{/* No name, no fingerprintable detail — just enough for a reader's tooling. */}
<meta name="author" content={IDENTITY.name} />
<meta name="generator" content={Astro.generator} />

static mirror of HEAD · about · clone: git clone https://git.makefuture.ro/eratic.git