Skip to content

Commit

Permalink
Merge pull request #19 from charlotte-hues/feature/codepen-integration
Browse files Browse the repository at this point in the history
Feat/Codepen Compatibility
  • Loading branch information
nicolashmln authored Dec 9, 2023
2 parents 641d2a9 + 12a2de8 commit e151e56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Strapi plugin oEmbed

Embed content from third party sites (Youtube, Vimeo, Tiktok, Soundcloud, Spotify...) for https://strapi.io v4 (For strapi v3 use v0.4.0)
Embed content from third party sites (Youtube, Vimeo, Tiktok, Soundcloud, Spotify, CodePen...) for https://strapi.io v4 (For strapi v3 use v0.4.0)

![](demo.gif)

Expand Down Expand Up @@ -87,6 +87,7 @@ If you paste the url `https://www.youtube.com/watch?v=tkiOqSTVGds` in the modal,
- Tiktok
- Soundcloud
- Spotify
- CodePen
- Twitter

Feel free to submit a PR with the provider you want, you just have to edit this file: `server/services/oembed.js`.
Expand Down
2 changes: 1 addition & 1 deletion admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"form.button.delete": "Delete",
"modal.import.title": "Import oEmbed content",
"modal.import.input.label": "URL",
"modal.import.input.description": "Youtube, Vimeo, Tiktok, Twitter, Soundcloud or Spotify",
"modal.import.input.description": "Youtube, Vimeo, Tiktok, Twitter, Soundcloud, Spotify or CodePen",
"modal.import.button.import": "Import"
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "strapi-plugin-oembed",
"version": "1.2.0",
"version": "1.2.1",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud, Spotify...) in Strapi",
"strapi": {
"name": "oembed",
"displayName": "oEmbed",
"icon": "globe-asia",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud, Spotify...) in Strapi",
"description": "Embed content from third party sites (YouTube, Vimeo, SoundCloud, Spotify, CodePen...) in Strapi",
"kind": "plugin"
},
"dependencies": {},
Expand All @@ -29,7 +29,9 @@
"vimeo",
"tiktok",
"soundcloud",
"spotify"
"spotify",
"codepen",
"twitter"
],
"peerDependencies": {
"@strapi/strapi": "^4.4.0"
Expand Down
12 changes: 9 additions & 3 deletions server/services/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module.exports = (
async fetch(url) {
let data;


const matches = url.match(/^(https?:\/\/)?(www\.)?(youtu\.be|youtube\.com|soundcloud\.com|vimeo\.com|tiktok\.com|open\.spotify\.com|twitter\.com)/i);
const matches = url.match(/^(https?:\/\/)?(www\.)?(youtu\.be|youtube\.com|soundcloud\.com|vimeo\.com|tiktok\.com|open\.spotify\.com|twitter\.com|codepen\.io)/i);

if (matches) {
try {
Expand Down Expand Up @@ -69,6 +68,13 @@ module.exports = (
mime = 'audio/spotify';
thumbnail = fetchedData.thumbnail_url;
break;

case 'codepen.io':
fetchedData = await axios.get(`https://codepen.io/api/oembed?format=json&url=${encodeURIComponent(url)}`).then((res) => res.data);
title = fetchedData.title;
mime = 'application/codepen';
thumbnail = fetchedData.thumbnail_url;
break;

default:
break;
Expand Down Expand Up @@ -104,4 +110,4 @@ module.exports = (
return data;
}
};
};
};

0 comments on commit e151e56

Please sign in to comment.