Skip to content

Commit

Permalink
Merge pull request #727 from microlinkhq/next
Browse files Browse the repository at this point in the history
refactor: remove $twitter helper
  • Loading branch information
Kikobeats authored Oct 18, 2024
2 parents 544509c + 683083d commit 9fa87f0
Show file tree
Hide file tree
Showing 17 changed files with 17,867 additions and 1,577 deletions.
9 changes: 5 additions & 4 deletions packages/metascraper-audio/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {
audio,
findRule,
has,
$twitter,
loadIframe,
normalizeUrl,
toRule
Expand Down Expand Up @@ -59,11 +58,13 @@ const audioRules = [
: undefined
},
({ url, htmlDom: $ }) => {
const src = $twitter($, 'twitter:player:stream')
const src = $('meta[name="twitter:player:stream"]').attr('content')
return src
? audio(src, {
url,
type: $twitter($, 'twitter:player:stream:content_type')
type: $('meta[name="twitter:player:stream:content_type"]').attr(
'content'
)
})
: undefined
},
Expand Down Expand Up @@ -99,7 +100,7 @@ module.exports = ({ getIframe = _getIframe } = {}) => {
).then(({ value }) => value)
},
async ({ htmlDom: $, url }) => {
const src = $twitter($, 'twitter:player')
const src = $('meta[name="twitter:player"]').attr('content')
return src
? findRule(audioRules, {
htmlDom: await getIframe(url, $, { src }),
Expand Down
4 changes: 2 additions & 2 deletions packages/metascraper-audio/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('og:audio:secure_url', async t => {

test('twitter:player', async t => {
const html =
'<meta property="twitter:player" content="https://twitter-card-player.vercel.app/container/audio.html">'
'<meta name="twitter:player" content="https://twitter-card-player.vercel.app/container/audio.html">'
const url = 'https://twitter-card-player.vercel.app'
const metascraper = createMetascraper()
const metadata = await metascraper({ html, url })
Expand All @@ -43,7 +43,7 @@ test('twitter:player', async t => {

test('twitter:player:stream', async t => {
const html =
'<meta property="twitter:player:stream" content="https://cdn.microlink.io/file-examples/sample.mp3">'
'<meta name="twitter:player:stream" content="https://cdn.microlink.io/file-examples/sample.mp3">'
const url = 'https://twitter-card-player.vercel.app'
const metascraper = createMetascraper()
const metadata = await metascraper({ html, url })
Expand Down
5 changes: 0 additions & 5 deletions packages/metascraper-helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ const titleize = (src, opts = {}) => {
return title
}

const $twitter = ($, selector) =>
$(`meta[name="${selector}"]`).attr('content') ||
$(`meta[property="${selector}"]`).attr('content')

const $filter = ($, matchedEl, fn = $filter.fn) => {
let matched

Expand Down Expand Up @@ -496,7 +492,6 @@ const getUrls = input => String(input).match(urlRegexForMatch) ?? []
module.exports = {
$filter,
$jsonld,
$twitter,
absoluteUrl,
audio,
audioExtensions,
Expand Down
9 changes: 5 additions & 4 deletions packages/metascraper-iframe/src/from-twitter.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict'

const { $twitter, memoizeOne } = require('@metascraper/helpers')
const { memoizeOne } = require('@metascraper/helpers')
const { map } = require('lodash')

const getPlayerUrl = memoizeOne(
(_, $) => $twitter($, 'twitter:player'),
(_, $) => $('meta[name="twitter:player"]').attr('content'),
memoizeOne.EqualityUrlAndHtmlDom
)

const playerWidth = $ => $twitter($, 'twitter:player:width')
const playerWidth = $ => $('meta[name="twitter:player:width"]').attr('content')

const playerHeight = $ => $twitter($, 'twitter:player:height')
const playerHeight = $ =>
$('meta[name="twitter:player:height"]').attr('content')

const fromTwitter =
() =>
Expand Down
2 changes: 1 addition & 1 deletion packages/metascraper-manifest/test/snapshots/index.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Generated by [AVA](https://avajs.dev).
{
description: null,
lang: null,
logo: 'https://www.gstatic.com/youtube/img/branding/favicon/favicon_192x192.png',
logo: 'https://www.gstatic.com/youtube/img/branding/favicon/favicon_192x192_v2.png',
publisher: 'YouTube',
}

Expand Down
Binary file modified packages/metascraper-manifest/test/snapshots/index.js.snap
Binary file not shown.
9 changes: 5 additions & 4 deletions packages/metascraper-video/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const {
$jsonld,
$twitter,
findRule,
has,
loadIframe,
Expand Down Expand Up @@ -58,11 +57,13 @@ const videoRules = [
: undefined
},
({ url, htmlDom: $ }) => {
const src = $twitter($, 'twitter:player:stream')
const src = $('meta[name="twitter:player:stream"]').attr('content')
return src
? video(src, {
url,
type: $twitter($, 'twitter:player:stream:content_type')
type: $('meta[name="twitter:player:stream:content_type"]').attr(
'content'
)
})
: undefined
},
Expand Down Expand Up @@ -98,7 +99,7 @@ const withIframe = (rules, getIframe) =>
).then(({ value }) => value)
},
async ({ htmlDom: $, url }) => {
const src = $twitter($, 'twitter:player')
const src = $('meta[name="twitter:player"]').attr('content')
return src
? findRule(rules, {
htmlDom: await getIframe(url, $, { src }),
Expand Down
4 changes: 2 additions & 2 deletions packages/metascraper-video/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('og:video:secure_url', async t => {

test('twitter:player', async t => {
const html =
'<meta property="twitter:player" content="https://twitter-card-player.vercel.app/container/video.html">'
'<meta name="twitter:player" content="https://twitter-card-player.vercel.app/container/video.html">'
const url = 'https://twitter-card-player.vercel.app'
const metascraper = createMetascraper()
const metadata = await metascraper({ html, url })
Expand All @@ -45,7 +45,7 @@ test('twitter:player', async t => {

test('twitter:player:stream', async t => {
const html =
'<meta property="twitter:player:stream" content="https://cdn.microlink.io/file-examples/sample.mp4">'
'<meta name="twitter:player:stream" content="https://cdn.microlink.io/file-examples/sample.mp4">'
const url = 'https://twitter-card-player.vercel.app'
const metascraper = createMetascraper()
const metadata = await metascraper({ html, url })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const url =

test('business-today', async t => {
const html = await readFile(resolve(__dirname, 'input.html'))
const metadata = await metascraper({ html, url })
const { date, ...metadata } = await metascraper({ html, url })
t.is(typeof date, 'string')
t.snapshot(metadata)
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Generated by [AVA](https://avajs.dev).
{
audio: null,
author: null,
date: '2016-05-18T10:09:00.000Z',
description: 'HackerRank is helping companies recruit coding champions through online tests.',
image: 'http://media2.intoday.in/btmt/images/stories/code505_051616043033.jpg',
lang: 'en',
Expand Down
Binary file not shown.
Loading

0 comments on commit 9fa87f0

Please sign in to comment.