diff --git a/built/general.js b/built/general.js index 16b3cd7..c92d25c 100644 --- a/built/general.js +++ b/built/general.js @@ -123,8 +123,15 @@ export default async (_url, lang = null) => { const url = typeof _url === 'string' ? new URL(_url) : _url; const res = await scpaping(url.href, { lang: lang || undefined }); 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') || + $('meta[name="twitter:title"]').attr('content') || $('meta[property="twitter:title"]').attr('content') || $('title').text(); if (title === undefined || title === null) { @@ -132,25 +139,27 @@ export default async (_url, lang = null) => { } title = clip(decodeHtml(title), 100); let image = $('meta[property="og:image"]').attr('content') || + $('meta[name="twitter:image"]').attr('content') || $('meta[property="twitter:image"]').attr('content') || $('link[rel="image_src"]').attr('href') || $('link[rel="apple-touch-icon"]').attr('href') || $('link[rel="apple-touch-icon image_src"]').attr('href'); image = image ? (new URL(image, url.href)).href : null; - const playerUrl = (twitterCard !== 'summary_large_image' && $('meta[property="twitter:player"]').attr('content')) || - (twitterCard !== 'summary_large_image' && $('meta[name="twitter:player"]').attr('content')) || + const playerUrl = (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:secure_url"]').attr('content') || $('meta[property="og:video:url"]').attr('content'); - const playerWidth = parseInt($('meta[property="twitter:player:width"]').attr('content') || - $('meta[name="twitter:player:width"]').attr('content') || + const playerWidth = parseInt($('meta[name="twitter:player:width"]').attr('content') || + $('meta[property="twitter:player:width"]').attr('content') || $('meta[property="og:video:width"]').attr('content') || ''); - const playerHeight = parseInt($('meta[property="twitter:player:height"]').attr('content') || - $('meta[name="twitter:player:height"]').attr('content') || + const playerHeight = parseInt($('meta[name="twitter:player:height"]').attr('content') || + $('meta[property="twitter:player:height"]').attr('content') || $('meta[property="og:video:height"]').attr('content') || ''); let description = $('meta[property="og:description"]').attr('content') || + $('meta[name="twitter:description"]').attr('content') || $('meta[property="twitter:description"]').attr('content') || $('meta[name="description"]').attr('content'); description = description @@ -166,7 +175,9 @@ export default async (_url, lang = null) => { $('link[rel="icon"]').attr('href') || '/favicon.ico'; 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 target = new URL(path, url.href); try { diff --git a/src/general.ts b/src/general.ts index b398e08..646a441 100644 --- a/src/general.ts +++ b/src/general.ts @@ -217,7 +217,10 @@ export default async (_url: URL | string, lang: string | null = null): Promise { const target = new URL(path, url.href);