Add pinterest domain and asset domains for link preview support
Co-authored-by: ken@signal.org Co-authored-by: @cmswalker
This commit is contained in:
parent
2a5cd3e4ea
commit
4a8e0bd466
2 changed files with 41 additions and 4 deletions
|
@ -34,6 +34,9 @@ const SUPPORTED_DOMAINS = [
|
|||
'instagram.com',
|
||||
'www.instagram.com',
|
||||
'm.instagram.com',
|
||||
'pinterest.com',
|
||||
'www.pinterest.com',
|
||||
'pin.it',
|
||||
];
|
||||
function isLinkInWhitelist(link) {
|
||||
try {
|
||||
|
@ -58,7 +61,7 @@ function isLinkInWhitelist(link) {
|
|||
}
|
||||
}
|
||||
|
||||
const SUPPORTED_MEDIA_DOMAINS = /^([^.]+\.)*(ytimg.com|cdninstagram.com|redd.it|imgur.com|fbcdn.net)$/i;
|
||||
const SUPPORTED_MEDIA_DOMAINS = /^([^.]+\.)*(ytimg.com|cdninstagram.com|redd.it|imgur.com|fbcdn.net|pinimg.com)$/i;
|
||||
function isMediaLinkInWhitelist(link) {
|
||||
try {
|
||||
const url = new URL(link);
|
||||
|
@ -81,8 +84,8 @@ function isMediaLinkInWhitelist(link) {
|
|||
}
|
||||
}
|
||||
|
||||
const META_TITLE = /<meta\s+property="og:title"\s+content="([\s\S]+?)"\s*\/?\s*>/im;
|
||||
const META_IMAGE = /<meta\s+property="og:image"\s+content="([\s\S]+?)"\s*\/?\s*>/im;
|
||||
const META_TITLE = /<meta\s+property="og:title"[^>]+?content="([\s\S]+?)"[^>]*>/im;
|
||||
const META_IMAGE = /<meta\s+property="og:image"[^>]+?content="([\s\S]+?)"[^>]*>/im;
|
||||
function _getMetaTag(html, regularExpression) {
|
||||
const match = regularExpression.exec(html);
|
||||
if (match && match[1]) {
|
||||
|
|
|
@ -37,6 +37,12 @@ describe('Link previews', () => {
|
|||
isLinkInWhitelist('https://m.instagram.com/blah'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(isLinkInWhitelist('https://pinterest.com/blah'), true);
|
||||
assert.strictEqual(
|
||||
isLinkInWhitelist('https://www.pinterest.com/blah'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(isLinkInWhitelist('https://pin.it/blah'), true);
|
||||
});
|
||||
|
||||
it('returns false for subdomains', () => {
|
||||
|
@ -109,6 +115,10 @@ describe('Link previews', () => {
|
|||
isMediaLinkInWhitelist('https://i.imgur.com/something'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isMediaLinkInWhitelist('https://pinimg.com/something'),
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it('returns false for insecure protocol', () => {
|
||||
|
@ -130,6 +140,10 @@ describe('Link previews', () => {
|
|||
isMediaLinkInWhitelist('http://i.imgur.com/something'),
|
||||
false
|
||||
);
|
||||
assert.strictEqual(
|
||||
isMediaLinkInWhitelist('http://pinimg.com/something'),
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
it('returns false for other domains', () => {
|
||||
|
@ -192,7 +206,7 @@ describe('Link previews', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('returns html-decoded tag contents from Instagram', () => {
|
||||
it('returns html-decoded tag contents from Imgur', () => {
|
||||
const imgur = `
|
||||
<meta property="og:site_name" content="Imgur">
|
||||
<meta property="og:url" content="https://imgur.com/gallery/KFCL8fm">
|
||||
|
@ -211,6 +225,26 @@ describe('Link previews', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('returns html-decoded tag contents from Pinterest', () => {
|
||||
const pinterest = `
|
||||
<meta property="og:image" name="og:image" content="https://i.pinimg.com/736x/9a/9e/64/9a9e64ed6b42b0a0e480dded4579d940--yard-sale-mulches.jpg" data-app>
|
||||
<meta property="og:image:height" name="og:image:height" content="200" data-app>
|
||||
<meta property="og:image:width" name="og:image:width" content="300" data-app>
|
||||
<meta property="og:title" name="og:title" content="Inexpensive Landscaping Ideas" data-app>
|
||||
<meta property="og:type" name="og:type" content="pinterestapp:pin" data-app>
|
||||
<meta property="og:url" name="og:url" content="https://www.pinterest.com/pin/3166662212807634/" data-app>
|
||||
`;
|
||||
|
||||
assert.strictEqual(
|
||||
'Inexpensive Landscaping Ideas',
|
||||
getTitleMetaTag(pinterest)
|
||||
);
|
||||
assert.strictEqual(
|
||||
'https://i.pinimg.com/736x/9a/9e/64/9a9e64ed6b42b0a0e480dded4579d940--yard-sale-mulches.jpg',
|
||||
getImageMetaTag(pinterest)
|
||||
);
|
||||
});
|
||||
|
||||
it('returns only the first tag', () => {
|
||||
const html = `
|
||||
<meta property="og:title" content="First Second Third"><meta property="og:title" content="Fourth Fifth Sixth">
|
||||
|
|
Loading…
Add table
Reference in a new issue