Skip to content

Commit 089a0ad

Browse files
authored
feat: support <link rel=alternate type=application/activitypub+json> (#10)
* feat: support `<link rel=alternate type=application/activitypub+json>` * Update index.ts * build
1 parent 77dd565 commit 089a0ad

10 files changed

Lines changed: 46 additions & 0 deletions

File tree

built/general.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export default async (_url, lang = null) => {
165165
const favicon = $('link[rel="shortcut icon"]').attr('href') ||
166166
$('link[rel="icon"]').attr('href') ||
167167
'/favicon.ico';
168+
const activityPub = $('link[rel="alternate"][type="application/activitypub+json"]').attr('href') || null;
168169
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true';
169170
const find = async (path) => {
170171
const target = new URL(path, url.href);
@@ -201,5 +202,6 @@ export default async (_url, lang = null) => {
201202
},
202203
sitename: siteName || null,
203204
sensitive,
205+
activityPub,
204206
};
205207
};

built/plugins/amazon.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ export async function summarize(url) {
4040
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
4141
},
4242
sitename: 'Amazon',
43+
activityPub: null,
4344
};
4445
}

built/plugins/wikipedia.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ export async function summarize(url) {
3333
allow: [],
3434
},
3535
sitename: 'Wikipedia',
36+
activityPub: null,
3637
};
3738
}

built/summary.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ declare type Summary = {
2727
* Possibly sensitive
2828
*/
2929
sensitive?: boolean;
30+
/**
31+
* The url of the ActivityPub representation of that web page
32+
*/
33+
activityPub: string | null;
3034
};
3135
export default Summary;
3236
export declare type Player = {

src/general.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
203203
$('link[rel="icon"]').attr('href') ||
204204
'/favicon.ico';
205205

206+
const activityPub =
207+
$('link[rel="alternate"][type="application/activitypub+json"]').attr('href') || null;
208+
206209
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true'
207210

208211
const find = async (path: string) => {
@@ -244,5 +247,6 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
244247
},
245248
sitename: siteName || null,
246249
sensitive,
250+
activityPub,
247251
};
248252
};

src/plugins/amazon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ export async function summarize(url: URL): Promise<summary> {
5555
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
5656
},
5757
sitename: 'Amazon',
58+
activityPub: null,
5859
};
5960
}

src/plugins/wikipedia.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ export async function summarize(url: URL): Promise<summary> {
4242
allow: [],
4343
},
4444
sitename: 'Wikipedia',
45+
activityPub: null,
4546
};
4647
}

src/summary.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type Summary = {
3333
* Possibly sensitive
3434
*/
3535
sensitive?: boolean;
36+
37+
/**
38+
* The url of the ActivityPub representation of that web page
39+
*/
40+
activityPub: string | null;
3641
};
3742

3843
export default Summary;

test/htmls/activitypub.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<link rel="alternate" type="application/activitypub+json" href="https://misskey.test/notes/abcdefg">

test/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,27 @@ describe("oEmbed", () => {
369369
expect(summary.player.height).toBe(300);
370370
});
371371
});
372+
373+
describe('ActivityPub', () => {
374+
test('Basic', async () => {
375+
app = fastify();
376+
app.get('*', (request, reply) => {
377+
return reply.send(fs.createReadStream(_dirname + '/htmls/activitypub.html'));
378+
});
379+
await app.listen({ port });
380+
381+
const summary = await summaly(host);
382+
expect(summary.activityPub).toBe('https://misskey.test/notes/abcdefg');
383+
});
384+
385+
test('Null', async () => {
386+
app = fastify();
387+
app.get('*', (request, reply) => {
388+
return reply.send(fs.createReadStream(_dirname + '/htmls/basic.html'));
389+
});
390+
await app.listen({ port });
391+
392+
const summary = await summaly(host);
393+
expect(summary.activityPub).toBe(null);
394+
});
395+
});

0 commit comments

Comments
 (0)