Add fediverse creator tag support (#41)

* add Fediverse Creator

* Update README.md
This commit is contained in:
Leah 2025-02-02 02:59:18 +01:00 committed by GitHub
parent cc7ae8d00a
commit fc9f7db477
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 64 additions and 9 deletions

View File

@ -93,6 +93,7 @@ A Promise of an Object that contains properties below:
| **player** | *Player* | The player of the web page |
| **sensitive** | *boolean* | Whether the url is sensitive |
| **activityPub** | *string* \| *null* | The url of the ActivityPub representation of that web page |
| **fediverseCreator** | *string* \| *null* | The pages fediverse handle |
| **url** | *string* | The url of the web page |
#### Summary

View File

@ -251,6 +251,9 @@ export async function parseGeneral(_url: URL | string, res: Awaited<ReturnType<t
const activityPub =
$('link[rel="alternate"][type="application/activity+json"]').attr('href') || null;
const fediverseCreator: string | null =
$('meta[name=\'fediverse:creator\']').attr('content') || null;
// https://developer.mixi.co.jp/connect/mixi_plugin/mixi_check/spec_mixi_check/#toc-18-
const sensitive =
$('meta[property=\'mixi:content-rating\']').attr('content') === '1' ||
@ -299,5 +302,6 @@ export async function parseGeneral(_url: URL | string, res: Awaited<ReturnType<t
sitename: siteName || null,
sensitive,
activityPub,
fediverseCreator,
};
}

View File

@ -38,6 +38,11 @@ type Summary = {
* The url of the ActivityPub representation of that web page
*/
activityPub: string | null;
/**
* The @ handle of a fediverse user (https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/)
*/
fediverseCreator: string | null;
};
export type SummalyResult = Summary & {

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="fediverse:creator" content="@test@example.com">
<title>Meow</title>
</head>
<body>
<h1>Hellooo!</h1>
<p>:3</p>
</body>
</html>

View File

@ -73,6 +73,7 @@ test('basic', async () => {
sensitive: false,
url: host + '/',
activityPub: null,
fediverseCreator: null,
});
});
@ -102,6 +103,7 @@ test('Stage Bye Stage', async () => {
'sitename': 'YouTube',
'sensitive': false,
'activityPub': null,
'fediverseCreator': null,
'url': 'https://www.youtube.com/watch?v=NMIEAhH_fTU',
},
);
@ -507,6 +509,36 @@ describe('ActivityPub', () => {
});
});
describe('Fediverse Creator', () => {
test('Basic', async () => {
app = fastify();
app.get('*', (request, reply) => {
const content = fs.readFileSync(_dirname + '/htmls/fediverse-creator.html');
reply.header('content-length', content.length);
reply.header('content-type', 'text/html');
return reply.send(content);
});
await app.listen({ port });
const summary = await summaly(host);
expect(summary.fediverseCreator).toBe('@test@example.com');
});
test('Null', async () => {
app = fastify();
app.get('*', (request, reply) => {
const content = fs.readFileSync(_dirname + '/htmls/basic.html');
reply.header('content-length', content.length);
reply.header('content-type', 'text/html');
return reply.send(content);
});
await app.listen({ port });
const summary = await summaly(host);
expect(summary.fediverseCreator).toBeNull();
});
});
describe('sensitive', () => {
test('default', async () => {
app = fastify();