generated from ryansonshine/typescript-npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use video player only for embedded videos (#60)
- Loading branch information
1 parent
2ad2ab1
commit eb26c07
Showing
8 changed files
with
137 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { setLogLevel } from "../log"; | ||
import { NotionBlock } from "../types"; | ||
import { standardVideoTransformer } from "./VideoTransformer"; | ||
import { blocksToMarkdown } from "./pluginTestRun"; | ||
|
||
test("youtube embedded", async () => { | ||
const config = { plugins: [standardVideoTransformer] }; | ||
const result = await blocksToMarkdown(config, [ | ||
{ | ||
object: "block", | ||
type: "video", | ||
video: { | ||
caption: [ | ||
{ | ||
type: "text", | ||
text: { | ||
content: "A video about editing in Notion", | ||
link: null, | ||
}, | ||
plain_text: "A video about editing in Notion", | ||
href: null, | ||
}, | ||
], | ||
type: "external", | ||
external: { url: "https://www.youtube.com/watch?v=FXIrojSK3Jo" }, | ||
}, | ||
} as unknown as NotionBlock, | ||
]); | ||
expect(result).toContain(`import ReactPlayer from "react-player";`); | ||
expect(result).toContain( | ||
`<ReactPlayer controls url="https://www.youtube.com/watch?v=FXIrojSK3Jo" />` | ||
); | ||
}); | ||
|
||
test("vimeo embedded", async () => { | ||
setLogLevel("verbose"); | ||
const config = { plugins: [standardVideoTransformer] }; | ||
const result = await blocksToMarkdown(config, [ | ||
{ | ||
object: "block", | ||
type: "video", | ||
video: { | ||
caption: [], | ||
type: "external", | ||
external: { url: "https://vimeo.com/4613611xx" }, | ||
}, | ||
} as unknown as NotionBlock, | ||
]); | ||
expect(result).toContain(`import ReactPlayer from "react-player";`); | ||
expect(result).toContain( | ||
`<ReactPlayer controls url="https://vimeo.com/4613611xx" />` | ||
); | ||
}); | ||
|
||
test("video link, not embedded", async () => { | ||
setLogLevel("verbose"); | ||
const config = { plugins: [standardVideoTransformer] }; | ||
const result = await blocksToMarkdown(config, [ | ||
{ | ||
object: "block", | ||
type: "paragraph", | ||
paragraph: { | ||
rich_text: [ | ||
{ | ||
type: "text", | ||
text: { | ||
content: "https://vimeo.com/4613611xx", | ||
link: { | ||
url: "https://vimeo.com/4613611xx", | ||
}, | ||
}, | ||
annotations: { | ||
code: false, | ||
}, | ||
plain_text: "https://vimeo.com/4613611xx", | ||
href: "https://vimeo.com/4613611xx", | ||
}, | ||
], | ||
color: "default", | ||
}, | ||
} as unknown as NotionBlock, | ||
]); | ||
expect(result).toContain( | ||
"[https://vimeo.com/4613611xx](https://vimeo.com/4613611xx)" | ||
); | ||
expect(result).not.toContain(`import`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { IPlugin } from "./pluginTypes"; | ||
|
||
export const standardVideoTransformer: IPlugin = { | ||
name: "video", | ||
notionToMarkdownTransforms: [ | ||
{ | ||
type: "video", | ||
getStringFromBlock: async (context, block) => { | ||
const blockAsAny = block as any; | ||
if (blockAsAny?.video?.external?.url) { | ||
context.imports = [`import ReactPlayer from "react-player";`]; | ||
return `<ReactPlayer controls url="${ | ||
blockAsAny.video.external.url as string | ||
}" />`; | ||
} else return await context.notionToMarkdown.blockToMarkdown(block); | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters