Skip to content

πŸŽ₯ Make videos programmatically with React

add .md routes

Igor Samokhovetsfa858463869f
diff --git a/packages/docs/.gitignore b/packages/docs/.gitignore
index 29990c0cb4..16e618a66a 100644
--- a/packages/docs/.gitignore
+++ b/packages/docs/.gitignore
@@ -7,6 +7,7 @@
# Generated files
.docusaurus
.cache-loader
+static/_raw
# Misc
.DS_Store
@@ -20,3 +21,4 @@ yarn-debug.log*
yarn-error.log*
out
+.vercel
diff --git a/packages/docs/copy-raw-docs.ts b/packages/docs/copy-raw-docs.ts
new file mode 100644
index 0000000000..f945d65c71
--- /dev/null
+++ b/packages/docs/copy-raw-docs.ts
@@ -0,0 +1,52 @@
+import fs from 'fs';
+import path from 'path';
+
+const DOCS_DIR = path.join(__dirname, 'docs');
+const OUTPUT_DIR = path.join(__dirname, 'static', '_raw', 'docs');
+
+function getAllMdxFiles(dir: string, baseDir: string = dir): string[] {
+ const files: string[] = [];
+ const entries = fs.readdirSync(dir, {withFileTypes: true});
+
+ for (const entry of entries) {
+ const fullPath = path.join(dir, entry.name);
+ if (entry.isDirectory()) {
+ files.push(...getAllMdxFiles(fullPath, baseDir));
+ } else if (entry.name.endsWith('.mdx')) {
+ const relativePath = path.relative(baseDir, fullPath);
+ files.push(relativePath);
+ }
+ }
+
+ return files;
+}
+
+function copyRawDocs() {
+ console.log('πŸ“„ Copying raw docs to static/_raw/docs/...');
+
+ if (fs.existsSync(OUTPUT_DIR)) {
+ fs.rmSync(OUTPUT_DIR, {recursive: true});
+ }
+
+ fs.mkdirSync(OUTPUT_DIR, {recursive: true});
+
+ const mdxFiles = getAllMdxFiles(DOCS_DIR);
+
+ let copiedCount = 0;
+ for (const file of mdxFiles) {
+ const sourcePath = path.join(DOCS_DIR, file);
+ const destPath = path.join(OUTPUT_DIR, file).replace(/\.mdx$/, '.md');
+
+ const destDir = path.dirname(destPath);
+ if (!fs.existsSync(destDir)) {
+ fs.mkdirSync(destDir, {recursive: true});
+ }
+
+ fs.copyFileSync(sourcePath, destPath);
+ copiedCount++;
+ }
+
+ console.log(`βœ… Copied ${copiedCount} files to static/_raw/docs/`);
+}
+
+copyRawDocs();
diff --git a/packages/docs/package.json b/packages/docs/package.json
index b6b6cc5be5..3b1706e702 100644
--- a/packages/docs/package.json
+++ b/packages/docs/package.json
@@ -9,7 +9,7 @@
"formatting": "prettier --experimental-cli src --check",
"docusaurus": "docusaurus",
"start": "bun update-prompt.ts && cd .. && bun run build && cd docs && docusaurus start --host 0.0.0.0",
- "build-docs": "DOCUSAURUS_IGNORE_SSG_WARNINGS=true docusaurus build && bun copy-convert.ts && bun count-pages.ts",
+ "build-docs": "DOCUSAURUS_IGNORE_SSG_WARNINGS=true docusaurus build && bun copy-raw-docs.ts && bun copy-convert.ts && bun count-pages.ts",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"serve": "docusaurus serve",
diff --git a/packages/docs/vercel.json b/packages/docs/vercel.json
index 8de54730b6..dd61b3a825 100644
--- a/packages/docs/vercel.json
+++ b/packages/docs/vercel.json
@@ -1,5 +1,13 @@
{
"headers": [
+ {
+ "source": "/_raw/docs/(.*).md",
+ "headers": [
+ {"key": "Content-Type", "value": "text/plain; charset=utf-8"},
+ {"key": "Access-Control-Allow-Origin", "value": "*"},
+ {"key": "Vary", "value": "Accept"}
+ ]
+ },
{
"source": "/img/gt-planar(.*)",
"headers": [
@@ -472,6 +480,10 @@
"source": "/docs/audio",
"destination": "/docs/html5-audio",
"permanent": false
+ },
+ {
+ "source": "/docs/:path*.md",
+ "destination": "/_raw/docs/:path*.md"
}
]
}