Compare commits
2 Commits
@portaljs/
...
jul-aug-up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92b12455c9 | ||
|
|
37902bfc71 |
@@ -1,11 +1,5 @@
|
|||||||
# @portaljs/remark-embed
|
# @portaljs/remark-embed
|
||||||
|
|
||||||
## 1.0.5
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- [`71716ab0`](https://github.com/datopian/portaljs/commit/71716ab01875f04f51bc23ba551c7a6a9a24a335) Thanks [@olayway](https://github.com/olayway)! - Add support for shortened yt links (https://youtu.be).
|
|
||||||
|
|
||||||
## 1.0.4
|
## 1.0.4
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@portaljs/remark-embed",
|
"name": "@portaljs/remark-embed",
|
||||||
"version": "1.0.5",
|
"version": "1.0.4",
|
||||||
"description": "Converts youtube link in mdx to an iframe embed",
|
"description": "Converts youtube link in mdx to an iframe embed",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,29 +1,14 @@
|
|||||||
import { visit } from "unist-util-visit";
|
import { visit } from "unist-util-visit";
|
||||||
|
|
||||||
// https://youtu.be/vDuh7vDgGIg
|
|
||||||
|
|
||||||
// TODO write tests!
|
|
||||||
function transformer(tree) {
|
function transformer(tree) {
|
||||||
visit(tree, "paragraph", (node) => {
|
visit(tree, "paragraph", (node) => {
|
||||||
visit(node, "text", (textNode) => {
|
visit(node, "text", (textNode) => {
|
||||||
if (
|
if (
|
||||||
(textNode.value.includes("https://www.youtube.com") ||
|
textNode.value.includes("https://www.youtube.com") &&
|
||||||
textNode.value.includes("https://youtu.be")
|
|
||||||
) &&
|
|
||||||
!textNode.value.includes("\n")
|
!textNode.value.includes("\n")
|
||||||
) {
|
) {
|
||||||
let videoId: string;
|
const urlSplit = textNode.value.split(/[=&]+/);
|
||||||
|
const iframeUrl = `https://www.youtube.com/embed/${urlSplit[1]}`;
|
||||||
if (textNode.value.includes("https://youtu.be")) {
|
|
||||||
// Extract video ID for short YT URLs
|
|
||||||
videoId = textNode.value.split("/").pop();
|
|
||||||
} else {
|
|
||||||
// Extract video ID for full YT URLs
|
|
||||||
const urlSplit = textNode.value.split(/[=&]+/);
|
|
||||||
videoId = urlSplit[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
const iframeUrl = `https://www.youtube.com/embed/${videoId}`;
|
|
||||||
Object.assign(node, {
|
Object.assign(node, {
|
||||||
...node,
|
...node,
|
||||||
type: "element",
|
type: "element",
|
||||||
|
|||||||
Reference in New Issue
Block a user