mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-04-29 02:37:27 +09:00
feat: support 'mixi:content-rating' for sensitive (#16)
* feat: support 'mixi:content-rating' for sensitive * fix: d7f6a88aee62510a0d3ba061f515e4688c34ca48 でビルドしてない * ビルドする
This commit is contained in:
parent
d7f6a88aee
commit
38000dd462
@ -123,8 +123,15 @@ export default async (_url, lang = null) => {
|
|||||||
const url = typeof _url === 'string' ? new URL(_url) : _url;
|
const url = typeof _url === 'string' ? new URL(_url) : _url;
|
||||||
const res = await scpaping(url.href, { lang: lang || undefined });
|
const res = await scpaping(url.href, { lang: lang || undefined });
|
||||||
const $ = res.$;
|
const $ = res.$;
|
||||||
const twitterCard = $('meta[property="twitter:card"]').attr('content');
|
const twitterCard = $('meta[name="twitter:card"]').attr('content') ||
|
||||||
|
$('meta[property="twitter:card"]').attr('content');
|
||||||
|
// According to docs, name attribute of meta tag is used for twitter card but for compatibility,
|
||||||
|
// this library will also look for property attribute.
|
||||||
|
// See https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/summary
|
||||||
|
// Property attribute is used for open graph.
|
||||||
|
// See https://ogp.me/
|
||||||
let title = $('meta[property="og:title"]').attr('content') ||
|
let title = $('meta[property="og:title"]').attr('content') ||
|
||||||
|
$('meta[name="twitter:title"]').attr('content') ||
|
||||||
$('meta[property="twitter:title"]').attr('content') ||
|
$('meta[property="twitter:title"]').attr('content') ||
|
||||||
$('title').text();
|
$('title').text();
|
||||||
if (title === undefined || title === null) {
|
if (title === undefined || title === null) {
|
||||||
@ -132,25 +139,27 @@ export default async (_url, lang = null) => {
|
|||||||
}
|
}
|
||||||
title = clip(decodeHtml(title), 100);
|
title = clip(decodeHtml(title), 100);
|
||||||
let image = $('meta[property="og:image"]').attr('content') ||
|
let image = $('meta[property="og:image"]').attr('content') ||
|
||||||
|
$('meta[name="twitter:image"]').attr('content') ||
|
||||||
$('meta[property="twitter:image"]').attr('content') ||
|
$('meta[property="twitter:image"]').attr('content') ||
|
||||||
$('link[rel="image_src"]').attr('href') ||
|
$('link[rel="image_src"]').attr('href') ||
|
||||||
$('link[rel="apple-touch-icon"]').attr('href') ||
|
$('link[rel="apple-touch-icon"]').attr('href') ||
|
||||||
$('link[rel="apple-touch-icon image_src"]').attr('href');
|
$('link[rel="apple-touch-icon image_src"]').attr('href');
|
||||||
image = image ? (new URL(image, url.href)).href : null;
|
image = image ? (new URL(image, url.href)).href : null;
|
||||||
const playerUrl = (twitterCard !== 'summary_large_image' && $('meta[property="twitter:player"]').attr('content')) ||
|
const playerUrl = (twitterCard !== 'summary_large_image' && $('meta[name="twitter:player"]').attr('content')) ||
|
||||||
(twitterCard !== 'summary_large_image' && $('meta[name="twitter:player"]').attr('content')) ||
|
(twitterCard !== 'summary_large_image' && $('meta[property="twitter:player"]').attr('content')) ||
|
||||||
$('meta[property="og:video"]').attr('content') ||
|
$('meta[property="og:video"]').attr('content') ||
|
||||||
$('meta[property="og:video:secure_url"]').attr('content') ||
|
$('meta[property="og:video:secure_url"]').attr('content') ||
|
||||||
$('meta[property="og:video:url"]').attr('content');
|
$('meta[property="og:video:url"]').attr('content');
|
||||||
const playerWidth = parseInt($('meta[property="twitter:player:width"]').attr('content') ||
|
const playerWidth = parseInt($('meta[name="twitter:player:width"]').attr('content') ||
|
||||||
$('meta[name="twitter:player:width"]').attr('content') ||
|
$('meta[property="twitter:player:width"]').attr('content') ||
|
||||||
$('meta[property="og:video:width"]').attr('content') ||
|
$('meta[property="og:video:width"]').attr('content') ||
|
||||||
'');
|
'');
|
||||||
const playerHeight = parseInt($('meta[property="twitter:player:height"]').attr('content') ||
|
const playerHeight = parseInt($('meta[name="twitter:player:height"]').attr('content') ||
|
||||||
$('meta[name="twitter:player:height"]').attr('content') ||
|
$('meta[property="twitter:player:height"]').attr('content') ||
|
||||||
$('meta[property="og:video:height"]').attr('content') ||
|
$('meta[property="og:video:height"]').attr('content') ||
|
||||||
'');
|
'');
|
||||||
let description = $('meta[property="og:description"]').attr('content') ||
|
let description = $('meta[property="og:description"]').attr('content') ||
|
||||||
|
$('meta[name="twitter:description"]').attr('content') ||
|
||||||
$('meta[property="twitter:description"]').attr('content') ||
|
$('meta[property="twitter:description"]').attr('content') ||
|
||||||
$('meta[name="description"]').attr('content');
|
$('meta[name="description"]').attr('content');
|
||||||
description = description
|
description = description
|
||||||
@ -166,7 +175,9 @@ export default async (_url, lang = null) => {
|
|||||||
$('link[rel="icon"]').attr('href') ||
|
$('link[rel="icon"]').attr('href') ||
|
||||||
'/favicon.ico';
|
'/favicon.ico';
|
||||||
const activityPub = $('link[rel="alternate"][type="application/activity+json"]').attr('href') || null;
|
const activityPub = $('link[rel="alternate"][type="application/activity+json"]').attr('href') || null;
|
||||||
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true';
|
// 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' ||
|
||||||
|
$('.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);
|
||||||
try {
|
try {
|
||||||
|
@ -217,7 +217,10 @@ export default async (_url: URL | string, lang: string | null = null): Promise<S
|
|||||||
const activityPub =
|
const activityPub =
|
||||||
$('link[rel="alternate"][type="application/activity+json"]').attr('href') || null;
|
$('link[rel="alternate"][type="application/activity+json"]').attr('href') || null;
|
||||||
|
|
||||||
const sensitive = $('.tweet').attr('data-possibly-sensitive') === 'true'
|
// 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' ||
|
||||||
|
$('.tweet').attr('data-possibly-sensitive') === 'true'
|
||||||
|
|
||||||
const find = async (path: string) => {
|
const find = async (path: string) => {
|
||||||
const target = new URL(path, url.href);
|
const target = new URL(path, url.href);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user