~james/core

core/web/src/lib/components/seo/Meta.svelte -rw-r--r-- 2.3 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
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
<script lang="ts">
	import { serializeJsonLd } from "#lib/seo/jsonLd.ts";

	interface Props {
		title?: string;
		description?: string;
		canonical?: string;
		type?: "website" | "profile" | "article";
		card?: "summary" | "summary_large_image";
		image?: string;
		video?: string;
		noindex?: boolean;
		jsonLd?: Record<string, unknown> | Array<Record<string, unknown>>;
	}

	let {
		title,
		description,
		canonical,
		type = "website",
		card = "summary_large_image",
		image,
		video,
		noindex = false,
		jsonLd
	}: Props = $props();

	const fullTitle = $derived(
		title
			? title.includes("·") || title.includes("&middot;")
				? title
				: `${title} · Tangled`
			: undefined
	);

	const schemas = $derived(jsonLd ? (Array.isArray(jsonLd) ? jsonLd : [jsonLd]) : []);
</script>

<svelte:head>
	{#if fullTitle}
		<title>{fullTitle}</title>
		<meta property="og:title" content={fullTitle} />
		<meta name="twitter:title" content={fullTitle} />
	{/if}
	{#if description}
		<meta name="description" content={description} />
		<meta property="og:description" content={description} />
		<meta name="twitter:description" content={description} />
	{/if}
	{#if canonical}
		<link rel="canonical" href={canonical} />
		<meta property="og:url" content={canonical} />
	{/if}
	{#if type}
		<meta property="og:type" content={type} />
	{/if}
	{#if card}
		<meta name="twitter:card" content={card} />
	{/if}
	<meta property="og:image" content={image || "https://assets.tangled.network/og-image.jpg"} />
	<meta property="og:image:width" content="1200" />
	<meta property="og:image:height" content="630" />
	<meta name="twitter:image" content={image || "https://assets.tangled.network/og-image.jpg"} />
	{#if video}
		<meta property="og:video" content={video} />
		<meta property="og:video:secure_url" content={video} />
		<meta property="og:video:type" content="video/mp4" />
		<meta property="og:video:width" content="1200" />
		<meta property="og:video:height" content="630" />
	{/if}
	{#if noindex}
		<meta name="robots" content="noindex, nofollow" />
	{/if}
	{#each schemas as schema (schema)}
		<!-- eslint-disable-next-line svelte/no-at-html-tags -- json-ld must be emitted as a script tag -->
		{@html `<script type="application/ld+json">${serializeJsonLd(schema)}<` + `/script>`}
	{/each}
</svelte:head>