Skip to content

🎥 Make videos programmatically with React

count pages

Jonny Burger6127bdb1dd26
diff --git a/packages/docs/count-pages.mjs b/packages/docs/count-pages.mjs
new file mode 100644
index 0000000000..114dd79ac7
--- /dev/null
+++ b/packages/docs/count-pages.mjs
@@ -0,0 +1,8 @@
+import path from "path";
+import { readDir } from "./get-pages.mjs";
+
+const root = path.join(process.cwd(), "docs");
+
+const pages = readDir(root);
+
+console.log(`There are ${pages.length} documentation pages.`);
diff --git a/packages/docs/extract-articles.mjs b/packages/docs/extract-articles.mjs
new file mode 100644
index 0000000000..a544e79766
--- /dev/null
+++ b/packages/docs/extract-articles.mjs
@@ -0,0 +1,51 @@
+import fs from "fs";
+import path from "path";
+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 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 relativePath = page.replace(process.cwd() + path.sep, "");
+ data.push({ id, title, relativePath });
+}
+
+fs.writeFileSync(
+ path.join(process.cwd(), "src", "data", "article.ts"),
+ JSON.stringify(data, null, 2)
+);
diff --git a/packages/docs/count-pages.js b/packages/docs/get-pages.mjs
similarity index 52%
rename from packages/docs/count-pages.js
rename to packages/docs/get-pages.mjs
index 76311f7325..8b5c4d9540 100644
--- a/packages/docs/count-pages.js
+++ b/packages/docs/get-pages.mjs
@@ -1,16 +1,12 @@
-const fs = require("fs");
-const path = require("path");
+import fs from "fs";
+import path from "path";
-const root = path.join(process.cwd(), "docs");
-
-const pages = [];
-
-const readDir = (dir) => {
+export const readDir = (dir, pages = []) => {
const docs = fs.readdirSync(dir);
for (const doc of docs) {
const stat = fs.statSync(path.join(dir, doc));
if (stat.isDirectory()) {
- readDir(path.join(dir, doc));
+ readDir(path.join(dir, doc), pages);
} else if (stat.isFile()) {
if (doc.includes("redirect")) {
continue;
@@ -19,8 +15,6 @@ const readDir = (dir) => {
pages.push(path.join(dir, doc));
}
}
-};
-readDir(root);
-
-console.log(`There are ${pages.length} documentation pages.`);
+ return pages;
+};
diff --git a/packages/docs/package.json b/packages/docs/package.json
index 93cb08b2bc..38e6b62a65 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -7,7 +7,7 @@
"start": "docusaurus start --host 0.0.0.0",
"start-docs": "docusaurus start",
"build": "tsc -d",
- "build-docs": "node --max_old_space_size=16000 node_modules/@docusaurus/core/bin/docusaurus.mjs build && node count-pages.js",
+ "build-docs": "node --max_old_space_size=16000 node_modules/@docusaurus/core/bin/docusaurus.mjs build && node count-pages.mjs",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"serve": "docusaurus serve",
diff --git a/packages/docs/src/remotion/Root.tsx b/packages/docs/src/remotion/Root.tsx
index d1d235c947..e4a536eb76 100644
--- a/packages/docs/src/remotion/Root.tsx
+++ b/packages/docs/src/remotion/Root.tsx
@@ -5,21 +5,24 @@ import { Expert } from "./Expert";
export const RemotionRoot: React.FC = () => {
return (
- <Folder name="experts">
- {experts.map((e) => {
- return (
- <Still
- key={e.slug}
- component={Expert}
- defaultProps={{
- expertId: e.slug,
- }}
- height={630}
- width={1200}
- id={`experts-${e.slug}`}
- />
- );
- })}
- </Folder>
+ <>
+ <Folder name="experts">
+ {experts.map((e) => {
+ return (
+ <Still
+ key={e.slug}
+ component={Expert}
+ defaultProps={{
+ expertId: e.slug,
+ }}
+ height={630}
+ width={1200}
+ id={`experts-${e.slug}`}
+ />
+ );
+ })}
+ </Folder>
+ <Folder name="articles" />
+ </>
);
};