Skip to content

Commit

Permalink
feat: support <link rel=alternate type=application/activitypub+json> (
Browse files Browse the repository at this point in the history
#10)

* feat: support `<link rel=alternate type=application/activitypub+json>`

* Update index.ts

* build
  • Loading branch information
saschanaz committed Jul 20, 2023
1 parent 77dd565 commit 089a0ad
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions built/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -201,5 +202,6 @@ export default async (_url, lang = null) => {
},
sitename: siteName || null,
sensitive,
activityPub,
};
};
1 change: 1 addition & 0 deletions built/plugins/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ export async function summarize(url) {
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
},
sitename: 'Amazon',
activityPub: null,
};
}
1 change: 1 addition & 0 deletions built/plugins/wikipedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export async function summarize(url) {
allow: [],
},
sitename: 'Wikipedia',
activityPub: null,
};
}
4 changes: 4 additions & 0 deletions built/summary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 4 additions & 0 deletions src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
$('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: string) => {
Expand Down Expand Up @@ -244,5 +247,6 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
},
sitename: siteName || null,
sensitive,
activityPub,
};
};
1 change: 1 addition & 0 deletions src/plugins/amazon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ export async function summarize(url: URL): Promise<summary> {
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
},
sitename: 'Amazon',
activityPub: null,
};
}
1 change: 1 addition & 0 deletions src/plugins/wikipedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export async function summarize(url: URL): Promise<summary> {
allow: [],
},
sitename: 'Wikipedia',
activityPub: null,
};
}
5 changes: 5 additions & 0 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/htmls/activitypub.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="alternate" type="application/activitypub+json" href="https://misskey.test/notes/abcdefg">
24 changes: 24 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 089a0ad

Please sign in to comment.