mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-04-29 02:37:27 +09:00
Add fediverse creator tag support (#41)
* add Fediverse Creator * Update README.md
This commit is contained in:
parent
cc7ae8d00a
commit
fc9f7db477
19
README.md
19
README.md
@ -85,15 +85,16 @@ A Promise of an Object that contains properties below:
|
||||
|
||||
| Property | Type | Description |
|
||||
|:----------------|:-------------------|:-----------------------------------------------------------|
|
||||
| **title** | *string* \| *null* | The title of the web page |
|
||||
| **icon** | *string* \| *null* | The url of the icon of the web page |
|
||||
| **description** | *string* \| *null* | The description of the web page |
|
||||
| **thumbnail** | *string* \| *null* | The url of the thumbnail of the web page |
|
||||
| **sitename** | *string* \| *null* | The name of the web site |
|
||||
| **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 |
|
||||
| **url** | *string* | The url of the web page |
|
||||
| **title** | *string* \| *null* | The title of the web page |
|
||||
| **icon** | *string* \| *null* | The url of the icon of the web page |
|
||||
| **description** | *string* \| *null* | The description of the web page |
|
||||
| **thumbnail** | *string* \| *null* | The url of the thumbnail of the web page |
|
||||
| **sitename** | *string* \| *null* | The name of the web site |
|
||||
| **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
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
@ -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 & {
|
||||
|
13
test/htmls/fediverse-creator.html
Normal file
13
test/htmls/fediverse-creator.html
Normal 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>
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user