Skip to content

Commit

Permalink
Merge pull request gfscott#189 from gfscott/simpler-url-parsing
Browse files Browse the repository at this point in the history
Simpler URL parsing
  • Loading branch information
gfscott authored Aug 4, 2023
2 parents 64f2227 + da38457 commit 77d525d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-suns-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eleventy-plugin-embed-ted": patch
---

Simpler regex and URL parsing
4 changes: 2 additions & 2 deletions packages/ted/lib/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*
* 1. Arbitrary whitespace
* 2. Arbitrary whitespace
* 3. The URL. It won't include anything after a trailing '/' character.
* 3. The URL path. It won't include anything after a trailing '/' character.
* 4. Arbitrary whitespace
* 5. Arbitrary whitespace
*/

module.exports = /<p>(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2((?:https?:)??(?:\/\/)??(?:w{3}\.)??(?:ted\.com\/talks\/[0-9a-zA-Z_]+))(?:\/?[^\s<>]*?)??(?=(\s*))\4(?:<\/a>)??(?=(\s*))\5<\/p>/g
module.exports = /<p>(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:)??(?:\/\/)??(?:w{3}\.)??(ted\.com\/talks\/[0-9a-zA-Z_]+)(?:\/?[^\s<>]*?)??(?=(\s*))\4(?:<\/a>)??(?=(\s*))\5<\/p>/g
4 changes: 1 addition & 3 deletions packages/ted/lib/replace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module.exports = function(match, config) {
const theUrl = match[3].startsWith('http') ? match[3] : `https://${match[3]}`;

const {pathname} = new URL(theUrl);
const {pathname} = new URL(`https://${match[3]}`);
const embedUrl = `https://embed.ted.com${pathname}`

let embed = `<div class="${config.embedClass}" style="${config.containerCss}">`
Expand Down

0 comments on commit 77d525d

Please sign in to comment.