Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fediverse creator tag support #41

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ export async function parseGeneral(_url: URL | string, opts?: GeneralScrapingOpt
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' ||
Expand Down Expand Up @@ -293,5 +296,6 @@ export async function parseGeneral(_url: URL | string, opts?: GeneralScrapingOpt
sitename: siteName || null,
sensitive,
activityPub,
fediverseCreator,
};
}
5 changes: 5 additions & 0 deletions src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down
13 changes: 13 additions & 0 deletions test/htmls/fediverse-creator.html
Original file line number Diff line number Diff line change
@@ -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>
32 changes: 32 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ test('basic', async () => {
sensitive: false,
url: host + '/',
activityPub: null,
fediverseCreator: null,
});
});

Expand Down Expand Up @@ -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',
},
);
Expand Down Expand Up @@ -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();
Expand Down
Loading