mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-04-29 02:37:27 +09:00
feat: support <link rel=alternate type=application/activitypub+json>
(#10)
* feat: support `<link rel=alternate type=application/activitypub+json>` * Update index.ts * build
This commit is contained in:
parent
77dd5654bb
commit
089a0ad8e8
@ -165,6 +165,7 @@ export default async (_url, lang = null) => {
|
|||||||
const favicon = $('link[rel="shortcut icon"]').attr('href') ||
|
const favicon = $('link[rel="shortcut icon"]').attr('href') ||
|
||||||
$('link[rel="icon"]').attr('href') ||
|
$('link[rel="icon"]').attr('href') ||
|
||||||
'/favicon.ico';
|
'/favicon.ico';
|
||||||
|
const activityPub = $('link[rel="alternate"][type="application/activitypub+json"]').attr('href') || null;
|
||||||
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true';
|
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true';
|
||||||
const find = async (path) => {
|
const find = async (path) => {
|
||||||
const target = new URL(path, url.href);
|
const target = new URL(path, url.href);
|
||||||
@ -201,5 +202,6 @@ export default async (_url, lang = null) => {
|
|||||||
},
|
},
|
||||||
sitename: siteName || null,
|
sitename: siteName || null,
|
||||||
sensitive,
|
sensitive,
|
||||||
|
activityPub,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -40,5 +40,6 @@ export async function summarize(url) {
|
|||||||
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
|
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
|
||||||
},
|
},
|
||||||
sitename: 'Amazon',
|
sitename: 'Amazon',
|
||||||
|
activityPub: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,5 +33,6 @@ export async function summarize(url) {
|
|||||||
allow: [],
|
allow: [],
|
||||||
},
|
},
|
||||||
sitename: 'Wikipedia',
|
sitename: 'Wikipedia',
|
||||||
|
activityPub: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
4
built/summary.d.ts
vendored
4
built/summary.d.ts
vendored
@ -27,6 +27,10 @@ declare type Summary = {
|
|||||||
* Possibly sensitive
|
* Possibly sensitive
|
||||||
*/
|
*/
|
||||||
sensitive?: boolean;
|
sensitive?: boolean;
|
||||||
|
/**
|
||||||
|
* The url of the ActivityPub representation of that web page
|
||||||
|
*/
|
||||||
|
activityPub: string | null;
|
||||||
};
|
};
|
||||||
export default Summary;
|
export default Summary;
|
||||||
export declare type Player = {
|
export declare type Player = {
|
||||||
|
@ -203,6 +203,9 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
|
|||||||
$('link[rel="icon"]').attr('href') ||
|
$('link[rel="icon"]').attr('href') ||
|
||||||
'/favicon.ico';
|
'/favicon.ico';
|
||||||
|
|
||||||
|
const activityPub =
|
||||||
|
$('link[rel="alternate"][type="application/activitypub+json"]').attr('href') || null;
|
||||||
|
|
||||||
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true'
|
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true'
|
||||||
|
|
||||||
const find = async (path: string) => {
|
const find = async (path: string) => {
|
||||||
@ -244,5 +247,6 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
|
|||||||
},
|
},
|
||||||
sitename: siteName || null,
|
sitename: siteName || null,
|
||||||
sensitive,
|
sensitive,
|
||||||
|
activityPub,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -55,5 +55,6 @@ export async function summarize(url: URL): Promise<summary> {
|
|||||||
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
|
allow: playerUrl ? ['fullscreen', 'encrypted-media'] : [],
|
||||||
},
|
},
|
||||||
sitename: 'Amazon',
|
sitename: 'Amazon',
|
||||||
|
activityPub: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -42,5 +42,6 @@ export async function summarize(url: URL): Promise<summary> {
|
|||||||
allow: [],
|
allow: [],
|
||||||
},
|
},
|
||||||
sitename: 'Wikipedia',
|
sitename: 'Wikipedia',
|
||||||
|
activityPub: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ type Summary = {
|
|||||||
* Possibly sensitive
|
* Possibly sensitive
|
||||||
*/
|
*/
|
||||||
sensitive?: boolean;
|
sensitive?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url of the ActivityPub representation of that web page
|
||||||
|
*/
|
||||||
|
activityPub: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Summary;
|
export default Summary;
|
||||||
|
3
test/htmls/activitypub.html
Normal file
3
test/htmls/activitypub.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<link rel="alternate" type="application/activitypub+json" href="https://misskey.test/notes/abcdefg">
|
@ -369,3 +369,27 @@ describe("oEmbed", () => {
|
|||||||
expect(summary.player.height).toBe(300);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user