tangled
alpha
login
or
join now
jauntywk.bsky.social
/
margin
forked from
margin.at/margin
0
fork
atom
Write on the margins of the internet. Powered by the AT Protocol.
0
fork
atom
overview
issues
pulls
pipelines
fix og yet again, im having so much fun!!!!!
scanash.com
1 month ago
1212667b
9097c40e
+21
-3
2 changed files
expand all
collapse all
unified
split
web
src
lib
og.ts
pages
og-image.ts
+11
-2
web/src/lib/og.ts
···
99
99
return str.slice(0, max - 3) + "...";
100
100
}
101
101
102
102
+
function extractBody(body: unknown): string {
103
103
+
if (!body) return "";
104
104
+
if (typeof body === "string") return body;
105
105
+
if (typeof body === "object" && body !== null && "value" in body) {
106
106
+
return String((body as { value: unknown }).value || "");
107
107
+
}
108
108
+
return "";
109
109
+
}
110
110
+
102
111
const BASE_URL = process.env.BASE_URL || "https://margin.at";
103
112
104
113
export async function fetchAnnotationOG(uri: string): Promise<OGData | null> {
···
118
127
const targetTitle = item.target?.title || item.title;
119
128
if (targetTitle) title = truncate(`Comment on: ${targetTitle}`, 60);
120
129
121
121
-
let description = item.body || item.bodyValue || item.text || "";
130
130
+
let description = extractBody(item.body) || item.bodyValue || item.text || "";
122
131
if (selectorText && description) {
123
132
description = `"${truncate(selectorText, 100)}"\n\n${description}`;
124
133
} else if (selectorText) {
···
186
195
const domain = extractDomain(source);
187
196
188
197
const title = item.title || item.target?.title || "Bookmark on Margin";
189
189
-
let description = item.description || item.body || item.bodyValue || "";
198
198
+
let description = item.description || extractBody(item.body) || item.bodyValue || "";
190
199
if (!description) description = "A saved bookmark on Margin";
191
200
if (domain) description += ` from ${domain}`;
192
201
description = truncate(description, 200);
+10
-1
web/src/pages/og-image.ts
···
79
79
: "";
80
80
const selectorText =
81
81
item.target?.selector?.exact || item.selector?.exact || "";
82
82
-
const bodyText = item.body || item.bodyValue || item.text || "";
82
82
+
const bodyText = extractBody(item.body) || item.bodyValue || item.text || "";
83
83
const motivation = item.motivation || "";
84
84
const targetTitle = item.target?.title || item.title || "";
85
85
···
164
164
function truncate(str: string, max: number): string {
165
165
if (str.length <= max) return str;
166
166
return str.slice(0, max - 3) + "...";
167
167
+
}
168
168
+
169
169
+
function extractBody(body: unknown): string {
170
170
+
if (!body) return "";
171
171
+
if (typeof body === "string") return body;
172
172
+
if (typeof body === "object" && body !== null && "value" in body) {
173
173
+
return String((body as { value: unknown }).value || "");
174
174
+
}
175
175
+
return "";
167
176
}
168
177
169
178
function avatarElement(url: string, author: string, size: number): unknown {