Skip to content

Commit a586af5

Browse files
fix(metascraper-instagram): prefer 180px apple-touch logo (#882)
rel=icon claims 192x192 but the file is 32x32. Use the 180 apple-touch icon Instagram already ships. Co-authored-by: Cursor <[email protected]>
1 parent 8b69a43 commit a586af5

4 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎packages/metascraper-instagram/src/index.js‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ const {
44
$meta,
55
author,
66
date,
7+
logo,
78
memoizeOne,
89
parseUrl,
9-
title
10+
title,
11+
toRule
1012
} = require('@metascraper/helpers')
1113

14+
const toLogo = toRule(logo)
15+
1216
const test = memoizeOne(
1317
url => parseUrl(url).domainWithoutSuffix === 'instagram'
1418
)
@@ -32,7 +36,13 @@ module.exports = () => {
3236
const dateString = `${dateMatch[1]} GMT`
3337
return date(new Date(dateString))
3438
},
35-
title: ({ htmlDom: $ }) => title($meta('twitter:title')($))
39+
title: ({ htmlDom: $ }) => title($meta('twitter:title')($)),
40+
// rel=icon claims 192x192 but the file is 32x32. The 180 apple-touch is real.
41+
logo: [
42+
toLogo($ =>
43+
$('link[rel="apple-touch-icon"][sizes="180x180"]').attr('href')
44+
)
45+
]
3646
}
3747

3848
rules.test = ({ url }) => test(url)

‎packages/metascraper-instagram/test/index.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ test('from igtv', async t => {
8484
t.snapshot(metadata)
8585
})
8686

87+
test('prefers apple-touch-icon 180 over a tiny favicon', async t => {
88+
const url = 'https://www.instagram.com/evolving.ai'
89+
const html = `<html><head>
90+
<link rel="icon" sizes="192x192" href="https://static.cdninstagram.com/rsrc.php/yr/r/rzWiSjZRxk5.webp">
91+
<link rel="apple-touch-icon" sizes="180x180" href="https://static.cdninstagram.com/rsrc.php/yw/r/icwX0xAk0pz.webp">
92+
<link rel="shortcut icon" href="https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico">
93+
</head></html>`
94+
const metadata = await metascraper({ url, html })
95+
t.is(
96+
metadata.logo,
97+
'https://static.cdninstagram.com/rsrc.php/yw/r/icwX0xAk0pz.webp'
98+
)
99+
})
100+
87101
test('from profile', async t => {
88102
const url = 'https://www.instagram.com/pluto__travel/'
89103
const html = await readFile(resolve(__dirname, 'fixtures/profile.html'))

‎packages/metascraper-instagram/test/snapshots/index.js.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Generated by [AVA](https://avajs.dev).
3131
- Sigue a OPPO @oppomobilees ¡Mucha suerte amig@s!”.`,
3232
image: 'https://scontent-mad2-1.cdninstagram.com/v/t51.29350-15/183037094_508540027000559_4927547535791161246_n.jpg?stp=c288.0.864.864a_dst-jpg_e35_s640x640_tt6&_nc_cat=104&ccb=1-7&_nc_sid=18de74&_nc_aid=0&_nc_ohc=Cie5q_gxLLYQ7kNvgEqiXD8&_nc_zt=23&_nc_ht=scontent-mad2-1.cdninstagram.com&_nc_gid=Ad8PSpquy5AZh1Pohh2JB72&oh=00_AYAE8CT9LyH7gYy8-q8TTXDRHsscgXiUHkz4a935bIIEmw&oe=67785396',
3333
lang: 'en',
34-
logo: 'https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico',
34+
logo: 'https://static.cdninstagram.com/rsrc.php/v4/yG/r/De-Dwpd5CHc.png',
3535
publisher: 'Instagram',
3636
title: 'Willyrex (@willyrex) • Instagram photos and videos',
3737
url: 'https://www.instagram.com/p/COn3M4TnRi1/',
@@ -49,7 +49,7 @@ Generated by [AVA](https://avajs.dev).
4949
Volumen 2 -3 de Diciembre @netflixes @netflix @vancouvermediaproducciones Vamos!!!!❤️❤️❤️❤️”.`,
5050
image: 'https://scontent-mad1-1.cdninstagram.com/v/t51.29350-15/191230544_467582901000109_7680987700811244011_n.jpg?stp=cmp1_dst-jpg_e35_s640x640_tt6&_nc_cat=105&ccb=1-7&_nc_sid=18de74&_nc_aid=0&_nc_ohc=kHLqxxCqPnoQ7kNvgFtd7Tr&_nc_zt=23&_nc_ht=scontent-mad1-1.cdninstagram.com&_nc_gid=AwDftrpFPN2gmnPrNcbD1K-&oh=00_AYDtTqr62Rie_rhcHZDF-_YhJbqfr33wUJWoEUZR307AIQ&oe=677834EB',
5151
lang: 'en',
52-
logo: 'https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico',
52+
logo: 'https://static.cdninstagram.com/rsrc.php/v4/yG/r/De-Dwpd5CHc.png',
5353
publisher: 'Instagram',
5454
title: 'Jaime Lorente (@jaimelorentelo) • Instagram video',
5555
url: 'https://www.instagram.com/p/CPQjO5RIIO9/',
@@ -65,7 +65,7 @@ Generated by [AVA](https://avajs.dev).
6565
description: '152K likes, 784 comments - jaimelorentelo on April 19, 2021',
6666
image: 'https://scontent-mad1-1.cdninstagram.com/v/t51.29350-15/174639953_2729961960649457_163277454509887310_n.jpg?stp=cmp1_dst-jpg_e35_s640x640_tt6&_nc_cat=106&ccb=1-7&_nc_sid=18de74&_nc_ohc=H2q9Sx_RfuUQ7kNvgGPxH-D&_nc_zt=23&_nc_ht=scontent-mad1-1.cdninstagram.com&_nc_gid=APNwiuVDNdm2x8RtNms_jnG&oh=00_AYAp3wmqC640nrO2IqWaoRN8eDpLuElVLqrJAuD4TqI9cw&oe=67783FE6',
6767
lang: 'en',
68-
logo: 'https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico',
68+
logo: 'https://static.cdninstagram.com/rsrc.php/v4/yG/r/De-Dwpd5CHc.png',
6969
publisher: 'Instagram',
7070
title: 'Jaime Lorente (@jaimelorentelo) • Instagram reel',
7171
url: 'https://www.instagram.com/reel/CN2VQ1yI_MA/',
@@ -81,7 +81,7 @@ Generated by [AVA](https://avajs.dev).
8181
description: '104K likes, 529 comments - jaimelorentelo on December 10, 2020: ”@primevideoes #romanceelcid”.',
8282
image: 'https://scontent-mad1-1.cdninstagram.com/v/t51.29350-15/130137754_387090089052277_2421356701080173583_n.jpg?stp=cmp1_dst-jpg_e35_s640x640_tt6&_nc_cat=101&ccb=1-7&_nc_sid=18de74&_nc_ohc=u9ofWKvAp2YQ7kNvgEj1AxX&_nc_zt=23&_nc_ht=scontent-mad1-1.cdninstagram.com&_nc_gid=AY0JeGfDYAelNBeg-tNTVE_&oh=00_AYDkvuMyKa1PLUKmVc2kYfWmVFIh_BCrryvxtTyEtoJUmA&oe=6778346B',
8383
lang: 'en',
84-
logo: 'https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico',
84+
logo: 'https://static.cdninstagram.com/rsrc.php/v4/yG/r/De-Dwpd5CHc.png',
8585
publisher: 'Instagram',
8686
title: 'Jaime Lorente (@jaimelorentelo) • Instagram video',
8787
url: 'https://www.instagram.com/tv/CIoLRFIIL50/',
@@ -97,7 +97,7 @@ Generated by [AVA](https://avajs.dev).
9797
description: '2,362 Followers, 136 Following, 224 Posts - See Instagram photos and videos from Pluto (@pluto__travel)',
9898
image: 'https://scontent-mad2-1.cdninstagram.com/v/t51.2885-19/133834346_403703180893250_1427065180629518897_n.jpg?stp=dst-jpg_s100x100_tt6&_nc_cat=110&ccb=1-7&_nc_sid=bf7eb4&_nc_ohc=_gRSHkYKjCoQ7kNvgF9HtMH&_nc_zt=24&_nc_ht=scontent-mad2-1.cdninstagram.com&oh=00_AYB0OOv_Wm1Vq3fV3qw3Du0X04mOC30p-CPX9z668Xl-sQ&oe=67786033',
9999
lang: 'en',
100-
logo: 'https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico',
100+
logo: 'https://static.cdninstagram.com/rsrc.php/v4/yG/r/De-Dwpd5CHc.png',
101101
publisher: 'Instagram',
102102
title: 'Pluto (@pluto__travel) • Instagram photos and videos',
103103
url: 'https://www.instagram.com/pluto__travel/',
@@ -113,7 +113,7 @@ Generated by [AVA](https://avajs.dev).
113113
description: '12M Followers, 3,160 Following, 688 Posts',
114114
image: 'https://scontent-mad2-1.cdninstagram.com/v/t51.2885-19/466429691_484017701330128_5602301276862352952_n.jpg?stp=dst-jpg_s206x206_tt6&_nc_cat=1&ccb=1-7&_nc_sid=bf7eb4&_nc_ohc=1xeqe0TO64YQ7kNvgEtl1ap&_nc_zt=24&_nc_ht=scontent-mad2-1.cdninstagram.com&oh=00_AYBGGubE2k4Gmcl25_6fqf3nzZwmh34U09nkX3IR6uqiCg&oe=67785D1F',
115115
lang: 'en',
116-
logo: 'https://static.cdninstagram.com/rsrc.php/y4/r/QaBlI0OZiks.ico',
116+
logo: 'https://static.cdninstagram.com/rsrc.php/v4/yG/r/De-Dwpd5CHc.png',
117117
publisher: 'Instagram',
118118
title: 'Watch this story by Jaime Lorente on Instagram before it disappears.',
119119
url: 'https://www.instagram.com/stories/jaimelorentelo/2591639087680304855/',
-45 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)