Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reddit embed added- New Feature #126

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
return null;
}

if (value === 'LL'
if (value === 'LL'
|| value.startsWith('RDMM')
|| value.startsWith('FL')) {
return null;
Expand Down Expand Up @@ -129,11 +129,18 @@ export default {
id: (ids) => ids.join('/embed/'),
},
instagram: {
regex: /https?:\/\/www\.instagram\.com\/p\/([^\/\?\&]+)\/?.*/,
//it support both reel and post
regex: /^https:\/\/(?:www\.)?instagram\.com\/(?:reel|p)\/(.*)/,
embedUrl: 'https://www.instagram.com/p/<%= remote_id %>/embed',
html: '<iframe width="400" height="505" style="margin: 0 auto;" frameborder="0" scrolling="no" allowtransparency="true"></iframe>',
height: 505,
width: 400,
id: (groups) => {
if (groups.length > 0) {
const item = groups[0].split("/");
return item[0];
}
},
},
twitter: {
regex: /^https?:\/\/(www\.)?twitter\.com\/.+\/status\/(\d+)/,
Expand Down Expand Up @@ -179,4 +186,12 @@ export default {
width: 600,
id: (groups) => `${groups.join('/')}.js`,
},
reddit: {
regex: /https:\/\/www\.reddit\.com\/(.*)/,
embedUrl: "https://www.redditmedia.com/<%= remote_id %>?ref_source=embed&ref=share&embed=true",
html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
height: 300,
width: 600,
id: (groups) => groups[0],
},
};
27 changes: 27 additions & 0 deletions test/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,33 @@ describe('Services Regexps', () => {
expect(embed.data.source).to.be.equal(url.source);
});
});

it('Reddit', async () => {
const service = 'reddit';

const urls = [
{
source: 'https://www.reddit.com/r/nextjs/comments/15lln9n/why_should_i_learn_nextjs/',
embed:'https://www.redditmedia.com/r/nextjs/comments/15lln9n/why_should_i_learn_nextjs/?ref_source=embed&ref=share&embed=true'
},
{
source: 'https://www.reddit.com/r/nextjs/comments/15lln9n/why_should_i_learn_nextjs/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button',
embed:'https://www.redditmedia.com/r/nextjs/comments/15lln9n/why_should_i_learn_nextjs/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button?ref_source=embed&ref=share&embed=true'
},
];

urls.forEach(url => {
expect(patterns[service].test(url.source)).to.be.true;

const event = composePasteEventMock('pattern', service, url.source);

embed.onPaste(event);

expect(embed.data.service).to.be.equal(service);
expect(embed.data.embed).to.be.equal(url.embed);
expect(embed.data.source).to.be.equal(url.source);
});
});
});

describe('Miro service', () => {
Expand Down
Loading