diff --git a/built/general.js b/built/general.js index 193a0e8..206b62d 100644 --- a/built/general.js +++ b/built/general.js @@ -165,6 +165,7 @@ export default async (_url, lang = null) => { const favicon = $('link[rel="shortcut icon"]').attr('href') || $('link[rel="icon"]').attr('href') || '/favicon.ico'; + const activityPub = $('link[rel="alternate"][type="application/activitypub+json"]').attr('href') || null; const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true'; const find = async (path) => { const target = new URL(path, url.href); @@ -201,5 +202,6 @@ export default async (_url, lang = null) => { }, sitename: siteName || null, sensitive, + activityPub, }; }; diff --git a/built/plugins/amazon.js b/built/plugins/amazon.js index 08796d4..87ceb79 100644 --- a/built/plugins/amazon.js +++ b/built/plugins/amazon.js @@ -40,5 +40,6 @@ export async function summarize(url) { allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [], }, sitename: 'Amazon', + activityPub: null, }; } diff --git a/built/plugins/wikipedia.js b/built/plugins/wikipedia.js index 4c85dfd..51800f9 100644 --- a/built/plugins/wikipedia.js +++ b/built/plugins/wikipedia.js @@ -33,5 +33,6 @@ export async function summarize(url) { allow: [], }, sitename: 'Wikipedia', + activityPub: null, }; } diff --git a/built/summary.d.ts b/built/summary.d.ts index 7a93ca7..27bf2bf 100644 --- a/built/summary.d.ts +++ b/built/summary.d.ts @@ -27,6 +27,10 @@ declare type Summary = { * Possibly sensitive */ sensitive?: boolean; + /** + * The url of the ActivityPub representation of that web page + */ + activityPub: string | null; }; export default Summary; export declare type Player = { diff --git a/src/general.ts b/src/general.ts index 81569a1..cd3f4e0 100644 --- a/src/general.ts +++ b/src/general.ts @@ -203,6 +203,9 @@ export default async (_url: URL | string, lang: string | null = null): Promise { @@ -244,5 +247,6 @@ export default async (_url: URL | string, lang: string | null = null): Promise { allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [], }, sitename: 'Amazon', + activityPub: null, }; } diff --git a/src/plugins/wikipedia.ts b/src/plugins/wikipedia.ts index 9249dac..28c5115 100644 --- a/src/plugins/wikipedia.ts +++ b/src/plugins/wikipedia.ts @@ -42,5 +42,6 @@ export async function summarize(url: URL): Promise { allow: [], }, sitename: 'Wikipedia', + activityPub: null, }; } diff --git a/src/summary.ts b/src/summary.ts index cc580cc..30c07f5 100644 --- a/src/summary.ts +++ b/src/summary.ts @@ -33,6 +33,11 @@ type Summary = { * Possibly sensitive */ sensitive?: boolean; + + /** + * The url of the ActivityPub representation of that web page + */ + activityPub: string | null; }; export default Summary; diff --git a/test/htmls/activitypub.html b/test/htmls/activitypub.html new file mode 100644 index 0000000..dc88c5f --- /dev/null +++ b/test/htmls/activitypub.html @@ -0,0 +1,3 @@ + + + diff --git a/test/index.ts b/test/index.ts index af86185..73aa552 100644 --- a/test/index.ts +++ b/test/index.ts @@ -369,3 +369,27 @@ describe("oEmbed", () => { expect(summary.player.height).toBe(300); }); }); + +describe('ActivityPub', () => { + test('Basic', async () => { + app = fastify(); + app.get('*', (request, reply) => { + return reply.send(fs.createReadStream(_dirname + '/htmls/activitypub.html')); + }); + await app.listen({ port }); + + const summary = await summaly(host); + expect(summary.activityPub).toBe('https://misskey.test/notes/abcdefg'); + }); + + test('Null', async () => { + app = fastify(); + app.get('*', (request, reply) => { + return reply.send(fs.createReadStream(_dirname + '/htmls/basic.html')); + }); + await app.listen({ port }); + + const summary = await summaly(host); + expect(summary.activityPub).toBe(null); + }); +});