Skip to content

🎥 Make videos programmatically with React

combine .mjs files for card rendering

MehmetAdemib8f1fe1eff0f
diff --git a/packages/docs/docs/contributing/bounty.md b/packages/docs/docs/contributing/bounty.md
index b6c4e16b7b..085cf52687 100644
--- a/packages/docs/docs/contributing/bounty.md
+++ b/packages/docs/docs/contributing/bounty.md
@@ -1,5 +1,5 @@
---
-image: /generated/articles-docs-contributing-docs.png
+image: /generated/articles-docs-contributing-bounty.png
title: How to take a bounty issue
sidebar_label: How to take a bounty issue
crumb: Contributing
@@ -17,7 +17,7 @@ Initially, there is no difference to a common contribution, that has no bounty.
## Before starting to solve the issue
-Bounties are paid through a third-party platform (i.e., <a href="https://algora.io/">Algora</a>). Before you start solving the issue, it’s recommended to create an account on Algora, where you also need to set up and connect your Stripe account. Once you have been assigned the issue and created an account on Algora, you are ready to go. You can start hacking.
+Bounties are paid through a third-party platform (i.e., Algora). Before you start solving the issue, it’s recommended to create an account on <a href="https://algora.io/">Algora</a>, where you also need to set up and connect your Stripe account. Once you have been assigned the issue and created an account on Algora, you are ready to go. You can start hacking.
## Start with hacking
diff --git a/packages/docs/docs/contributing/docs.md b/packages/docs/docs/contributing/docs.md
index 34162b7dbd..cca08e0a32 100644
--- a/packages/docs/docs/contributing/docs.md
+++ b/packages/docs/docs/contributing/docs.md
@@ -21,7 +21,7 @@ Each page has a button `Improve this page` at the bottom. This is the easiest wa
<Step>2</Step> Create a new <code>.md</code> document in the <code>packages/docs/docs</code> folder. <br/>
<Step>3</Step> Add the document to <code>packages/docs/sidebars.js</code>.<br/>
<Step>4</Step> Write what you have to say!<br/>
-<Step>5</Step> Run <code>node extract-articles.mjs</code> in <code>packages/docs</code> to generate preview cards that will show up if the documentation page is shared on social media.<br/>
+<Step>5</Step> Run <code>node render-cards.mjs</code> in <code>packages/docs</code> to generate preview cards that will show up if the documentation page is shared on social media.<br/>
## Language guidelines
diff --git a/packages/docs/docs/lambda/sqs.md b/packages/docs/docs/lambda/sqs.md
index 464ae126d3..e29b2b3727 100644
--- a/packages/docs/docs/lambda/sqs.md
+++ b/packages/docs/docs/lambda/sqs.md
@@ -1,5 +1,5 @@
---
-image: /generated/articles-docs-lambda-aws-sqs-lambda-integration.png
+image: /generated/articles-docs-lambda-sqs.png
title: Using Lambda with SQS
slug: /lambda/sqs
sidebar_label: Queueing with SQS
diff --git a/packages/docs/render-cards.mjs b/packages/docs/render-cards.mjs
index f419558885..463388337a 100644
--- a/packages/docs/render-cards.mjs
+++ b/packages/docs/render-cards.mjs
@@ -2,19 +2,130 @@ import { bundle } from "@remotion/bundler";
import { getCompositions, renderStill } from "@remotion/renderer";
import path from "path";
-const serveUrl = await bundle({
+// render cards
+const serveUrl_1 = await bundle({
entryPoint: path.join(process.cwd(), "./src/remotion/entry.ts"),
publicDir: path.join(process.cwd(), "static"),
});
-const compositions = await getCompositions(serveUrl);
+const compositions_1 = await getCompositions(serveUrl_1);
-for (const composition of compositions.filter(
+for (const composition of compositions_1.filter(
(c) => c.id.startsWith("expert") || c.id.startsWith("template")
)) {
await renderStill({
composition,
output: `static/generated/${composition.id}.png`,
- serveUrl,
+ serveUrl: serveUrl_1,
});
console.log("Rendered", composition.id);
}
+
+
+// extract articles
+import { execSync } from "child_process";
+import fs from "fs";
+import { readDir } from "./get-pages.mjs";
+
+const root = path.join(process.cwd(), "docs");
+
+const pages = readDir(root);
+
+const findId = (split, page) => {
+ const found = split.find((s) => s.startsWith("id: "));
+ if (found) {
+ return found.substr("id: ".length);
+ }
+
+ return page
+ .replace(process.cwd() + path.sep + "docs" + path.sep, "")
+ .replace(/.md$/, "");
+};
+
+const findTitle = (split) => {
+ const title = split
+ .find((s) => s.startsWith("title: "))
+ .replace(/^title:\s/, "");
+ if (title.startsWith('"')) {
+ return title.substr(1, title.length - 2);
+ }
+
+ return title;
+};
+
+const findCrumb = (split) => {
+ const crumb = split
+ .find((s) => s.startsWith("crumb: "))
+ ?.replace(/^crumb:\s/, "");
+ if (crumb?.startsWith('"')) {
+ return crumb.substr(1, crumb.length - 2);
+ }
+
+ return crumb ?? null;
+};
+
+const data = [];
+
+for (const page of pages) {
+ const opened = fs.readFileSync(page, "utf8");
+ const frontmatter = opened.match(/---\n((.|\n)*?)---\n/);
+ if (!frontmatter) {
+ continue;
+ }
+
+ const split = frontmatter[1].split("\n");
+ const id = findId(split, page);
+ const title = findTitle(split);
+ const crumb = findCrumb(split);
+
+ const relativePath = page.replace(process.cwd() + path.sep, "");
+ const compId =
+ "articles-" + relativePath.replace(/\//g, "-").replace(/.md$/, "");
+ data.push({ id, title, relativePath, compId, crumb });
+}
+
+fs.writeFileSync(
+ path.join(process.cwd(), "src", "data", "articles.ts"),
+ `export const articles = ` + JSON.stringify(data, null, 2)
+);
+
+execSync("pnpm exec prettier src/data/articles.ts --write");
+
+const serveUrl_2 = await bundle({
+ entryPoint: path.join(process.cwd(), "./src/remotion/entry.ts"),
+ publicDir: path.join(process.cwd(), "static"),
+});
+const compositions_2 = await getCompositions(serveUrl_2);
+
+for (const entry of data) {
+ const composition = compositions_2.find((c) => c.id === entry.compId);
+ const output = `static/generated/${composition.id}.png`;
+ if (fs.existsSync(output)) {
+ console.log("Existed", composition.id);
+ continue;
+ }
+
+ const out = path.join(process.cwd(), entry.relativePath);
+ await renderStill({
+ composition,
+ output,
+ serveUrl: serveUrl_2,
+ });
+
+ const fileContents = fs.readFileSync(out, "utf-8");
+ const lines = fileContents
+ .split("\n")
+ .filter((l) => !l.startsWith("image: "));
+ const frontmatterLine = lines.findIndex((l) => l === "---");
+ if (frontmatterLine === -1) {
+ throw new Error("could not find frontmatter for " + composition.id);
+ }
+
+ const newLines = [
+ ...lines.slice(0, frontmatterLine + 1),
+ `image: /${output.substring("/static".length)}`,
+ ...lines.slice(frontmatterLine + 1),
+ ].join("\n");
+
+ fs.writeFileSync(out, newLines);
+ console.log("Rendered", composition.id);
+}
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index d153a62386..b2c9d4d0f8 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -188,6 +188,13 @@ export const articles = [
compId: "articles-docs-continue-render",
crumb: "API",
},
+ {
+ id: "contributing/bounty",
+ title: "How to take a bounty issue",
+ relativePath: "docs/contributing/bounty.md",
+ compId: "articles-docs-contributing-bounty",
+ crumb: "Contributing",
+ },
{
id: "contributing/docs",
title: "Contributing to the documentation",
@@ -482,13 +489,6 @@ export const articles = [
compId: "articles-docs-lambda-authentication",
crumb: "Lambda",
},
- {
- id: "lambda/aws-sqs-lambda-integration",
- title: "Using Lambda with SQS",
- relativePath: "docs/lambda/aws-sqs-lambda-integration.md",
- compId: "articles-docs-lambda-aws-sqs-lambda-integration",
- crumb: "@remotion/lambda",
- },
{
id: "changelog",
title: "Prerelease Changelog",
@@ -832,6 +832,13 @@ export const articles = [
compId: "articles-docs-lambda-speed",
crumb: "Lambda",
},
+ {
+ id: "lambda/sqs",
+ title: "Using Lambda with SQS",
+ relativePath: "docs/lambda/sqs.md",
+ compId: "articles-docs-lambda-sqs",
+ crumb: "@remotion/lambda",
+ },
{
id: "bucket-disallows-acl",
title: "The bucket does not allow ACLs",
diff --git a/packages/docs/static/generated/articles-docs-contributing-bounty.png b/packages/docs/static/generated/articles-docs-contributing-bounty.png
new file mode 100644
index 0000000000..281b3b370c
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-contributing-bounty.png differ
diff --git a/packages/docs/static/generated/articles-docs-lambda-sqs.png b/packages/docs/static/generated/articles-docs-lambda-sqs.png
new file mode 100644
index 0000000000..68429e5a2b
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-lambda-sqs.png differ