Skip to content

Commit

Permalink
refactor: remove $twitter helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 18, 2024
1 parent 544509c commit 10bbe60
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 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
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
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

0 comments on commit 10bbe60

Please sign in to comment.