Skip to content

Commit ba98b18

Browse files
committed
feat: Handle direct Notion videos (#65)
1 parent 4606aff commit ba98b18

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

src/plugins/VideoTransformer.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,31 @@ test("video link, not embedded", async () => {
8585
);
8686
expect(result).not.toContain(`import`);
8787
});
88+
89+
test("direct upload to to Notion (embedded)", async () => {
90+
setLogLevel("verbose");
91+
const config = { plugins: [standardVideoTransformer] };
92+
const result = await blocksToMarkdown(config, [
93+
{
94+
object: "block",
95+
id: "12f7db3b-4412-4be9-a3f7-6ac423fee94a",
96+
parent: {
97+
type: "page_id",
98+
page_id: "edaffeb2-ece8-4d44-976f-351e6b5757bb",
99+
},
100+
101+
type: "video",
102+
video: {
103+
caption: [],
104+
type: "file",
105+
file: {
106+
url: "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/f6bc4746-011e-2124-86ca-ed4337d70891/people_fre_motionAsset_p3.mp4?X-Blah-blah",
107+
},
108+
},
109+
} as unknown as NotionBlock,
110+
]);
111+
expect(result).toContain(`import ReactPlayer from "react-player";`);
112+
expect(result).toContain(
113+
`<ReactPlayer controls url="https://s3.us-west-2.amazonaws.com/secure.notion-static.com/f6bc4746-011e-2124-86ca-ed4337d70891/people_fre_motionAsset_p3.mp4?X-Blah-blah" />`
114+
);
115+
});

src/plugins/VideoTransformer.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,24 @@ export const standardVideoTransformer: IPlugin = {
1313
block: NotionBlock
1414
): string => {
1515
const video = (block as VideoBlockObjectResponse).video;
16-
if (video.type === "external") {
17-
if (!context.imports) context.imports = [];
18-
context.imports.push(`import ReactPlayer from "react-player";`);
19-
return `<ReactPlayer controls url="${video.external.url}" />`;
20-
} else {
21-
warning(
22-
`[standardVideoTransformer] Found Notion "video" block with type ${video.type}. The best docu-notion can do for now is ignore it.`
23-
);
16+
let url = "";
17+
switch (video.type) {
18+
case "external":
19+
url = video.external.url;
20+
break;
21+
case "file":
22+
url = video.file.url;
23+
break;
24+
default:
25+
warning(
26+
`[standardVideoTransformer] Found Notion "video" block with type ${video.type}. The best docu-notion can do for now is ignore it.`
27+
);
28+
return "";
29+
break;
2430
}
25-
return "";
31+
32+
context.imports.push(`import ReactPlayer from "react-player";`);
33+
return `<ReactPlayer controls url="${url}" />`;
2634
},
2735
},
2836
],

src/plugins/pluginTestRun.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function blocksToMarkdown(
3636
convertNotionLinkToLocalDocusaurusLink: (url: string) => {
3737
return convertInternalUrl(docunotionContext, url);
3838
},
39+
imports: [],
3940

4041
//TODO might be needed for some tests, e.g. the image transformer...
4142
directoryContainingMarkdown: "not yet",

src/plugins/pluginTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ export type IDocuNotionContext = {
8080
// If the output is creating things like react elements, you can append their import definitions
8181
// to this array so they get added to the page.
8282
// e.g. context.imports.push(`import ReactPlayer from "react-player";`);
83-
imports?: string[];
83+
imports: string[];
8484
};

src/pull.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ async function outputPages(
111111
options: options,
112112
pages: pages,
113113
counts: counts, // review will this get copied or pointed to?
114+
imports: [],
114115
convertNotionLinkToLocalDocusaurusLink: (url: string) =>
115116
convertInternalUrl(context, url),
116117
};

0 commit comments

Comments
 (0)