summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/web/views/note.tsx
blob: 85657eb1ed49c904e9d0b82d6c993ce03a32602e (plain)
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
/*
 * SPDX-FileCopyrightText: syuilo and misskey-project
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import type { Packed } from '@/misc/json-schema.js';
import type { MiUserProfile } from '@/models/UserProfile.js';
import type { CommonProps } from '@/server/web/views/_.js';
import { Layout } from '@/server/web/views/base.js';
import { isRenotePacked } from '@/misc/is-renote.js';
import { getNoteSummary } from '@/misc/get-note-summary.js';

export function NotePage(props: CommonProps<{
	note: Packed<'Note'>;
	profile: MiUserProfile;
}>) {
	const title = props.note.user.name ? `${props.note.user.name} (@${props.note.user.username}${props.note.user.host ? `@${props.note.user.host}` : ''})` : `@${props.note.user.username}${props.note.user.host ? `@${props.note.user.host}` : ''}`
	const isRenote = isRenotePacked(props.note);
	const images = (props.note.files ?? []).filter(f => f.type.startsWith('image/'));
	const videos = (props.note.files ?? []).filter(f => f.type.startsWith('video/'));
	const summary = getNoteSummary(props.note);

	function ogBlock() {
		return (
			<>
				<meta property="og:type" content="article" />
				<meta property="og:title" content={title} />
				<meta property="og:description" content={summary} />
				<meta property="og:url" content={`${props.config.webUrl}/notes/${props.note.id}`} />
				{videos.map(video => (
					<>
						<meta property="og:video:url" content={video.url} />
						<meta property="og:video:secure_url" content={video.url} />
						<meta property="og:video:type" content={video.type} />
						{video.thumbnailUrl ? <meta property="og:video:image" content={video.thumbnailUrl} /> : null}
						{video.properties.width != null ? <meta property="og:video:width" content={video.properties.width.toString()} /> : null}
						{video.properties.height != null ? <meta property="og:video:height" content={video.properties.height.toString()} /> : null}
					</>
				))}
				{images.length > 0 ? (
					<>
						<meta property="twitter:card" content="summary_large_image" />
						{images.map(image => (
							<>
								<meta property="og:image" content={image.url} />
								{image.properties.width != null ? <meta property="og:image:width" content={image.properties.width.toString()} /> : null}
								{image.properties.height != null ? <meta property="og:image:height" content={image.properties.height.toString()} /> : null}
							</>
						))}
					</>
				) : (
					<>
						<meta property="twitter:card" content="summary" />
						<meta property="og:image" content={props.note.user.avatarUrl} />
					</>
				)}
			</>
		);
	}

	function metaBlock() {
		return (
			<>
				{props.note.user.host != null || isRenote || props.profile.noCrawle ? <meta name="robots" content="noindex" /> : null}
				{props.profile.preventAiLearning ? (
					<>
						<meta name="robots" content="noimageai" />
						<meta name="robots" content="noai" />
					</>
				) : null}
				<meta name="misskey:user-username" content={props.note.user.username} />
				<meta name="misskey:user-id" content={props.note.user.id} />
				<meta name="misskey:note-id" content={props.note.id} />

				{props.federationEnabled ? (
					<>
						{props.note.user.host == null ? <link rel="alternate" type="application/activity+json" href={`${props.config.webUrl}/notes/${props.note.id}`} /> : null}
						{props.note.uri != null ? <link rel="alternate" type="application/activity+json" href={props.note.uri} /> : null}
					</>
				) : null}
			</>
		);
	}

	return (
		<Layout
			{...props}
			title={`${title} | ${props.instanceName}`}
			desc={summary}
			metaSlot={metaBlock()}
			ogSlot={ogBlock()}
		></Layout>
	)
}