From 089a0ad8e8c780e5c088b1c528aa95c5827cbdcc Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 20 Jul 2023 08:36:26 +0200 Subject: [PATCH] feat: support `` (#10) * feat: support `` * Update index.ts * build --- built/general.js | 2 ++ built/plugins/amazon.js | 1 + built/plugins/wikipedia.js | 1 + built/summary.d.ts | 4 ++++ src/general.ts | 4 ++++ src/plugins/amazon.ts | 1 + src/plugins/wikipedia.ts | 1 + src/summary.ts | 5 +++++ test/htmls/activitypub.html | 3 +++ test/index.ts | 24 ++++++++++++++++++++++++ 10 files changed, 46 insertions(+) create mode 100644 test/htmls/activitypub.html diff --git a/built/general.js b/built/general.js index 193a0e88..206b62dc 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 08796d45..87ceb79d 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 4c85dfde..51800f95 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 7a93ca70..27bf2bf2 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 81569a14..cd3f4e01 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 9249dacc..28c5115d 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 cc580cc7..30c07f59 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 00000000..dc88c5f5 --- /dev/null +++ b/test/htmls/activitypub.html @@ -0,0 +1,3 @@ + + + diff --git a/test/index.ts b/test/index.ts index af86185b..73aa552a 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); + }); +});