Skip to content

Commit

Permalink
Merge pull request #69 from sillsdev/DirectNotionVideos
Browse files Browse the repository at this point in the history
feat: Handle direct Notion videos (#65)
  • Loading branch information
andrew-polk authored Aug 14, 2023
2 parents 4606aff + ba98b18 commit 2c5a365
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
28 changes: 28 additions & 0 deletions src/plugins/VideoTransformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,31 @@ test("video link, not embedded", async () => {
);
expect(result).not.toContain(`import`);
});

test("direct upload to to Notion (embedded)", async () => {
setLogLevel("verbose");
const config = { plugins: [standardVideoTransformer] };
const result = await blocksToMarkdown(config, [
{
object: "block",
id: "12f7db3b-4412-4be9-a3f7-6ac423fee94a",
parent: {
type: "page_id",
page_id: "edaffeb2-ece8-4d44-976f-351e6b5757bb",
},

type: "video",
video: {
caption: [],
type: "file",
file: {
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",
},
},
} as unknown as NotionBlock,
]);
expect(result).toContain(`import ReactPlayer from "react-player";`);
expect(result).toContain(
`<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" />`
);
});
26 changes: 17 additions & 9 deletions src/plugins/VideoTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ export const standardVideoTransformer: IPlugin = {
block: NotionBlock
): string => {
const video = (block as VideoBlockObjectResponse).video;
if (video.type === "external") {
if (!context.imports) context.imports = [];
context.imports.push(`import ReactPlayer from "react-player";`);
return `<ReactPlayer controls url="${video.external.url}" />`;
} else {
warning(
`[standardVideoTransformer] Found Notion "video" block with type ${video.type}. The best docu-notion can do for now is ignore it.`
);
let url = "";
switch (video.type) {
case "external":
url = video.external.url;
break;
case "file":
url = video.file.url;
break;
default:
warning(
`[standardVideoTransformer] Found Notion "video" block with type ${video.type}. The best docu-notion can do for now is ignore it.`
);
return "";
break;
}
return "";

context.imports.push(`import ReactPlayer from "react-player";`);
return `<ReactPlayer controls url="${url}" />`;
},
},
],
Expand Down
1 change: 1 addition & 0 deletions src/plugins/pluginTestRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export async function blocksToMarkdown(
convertNotionLinkToLocalDocusaurusLink: (url: string) => {
return convertInternalUrl(docunotionContext, url);
},
imports: [],

//TODO might be needed for some tests, e.g. the image transformer...
directoryContainingMarkdown: "not yet",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/pluginTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ export type IDocuNotionContext = {
// If the output is creating things like react elements, you can append their import definitions
// to this array so they get added to the page.
// e.g. context.imports.push(`import ReactPlayer from "react-player";`);
imports?: string[];
imports: string[];
};
1 change: 1 addition & 0 deletions src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async function outputPages(
options: options,
pages: pages,
counts: counts, // review will this get copied or pointed to?
imports: [],
convertNotionLinkToLocalDocusaurusLink: (url: string) =>
convertInternalUrl(context, url),
};
Expand Down

0 comments on commit 2c5a365

Please sign in to comment.