This repository was archived by the owner on Jun 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.js
More file actions
53 lines (41 loc) · 1.42 KB
/
Copy pathexec.js
File metadata and controls
53 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require("fs");
const path = require("path");
const dir = "./"; // Cambia se necessario
function processDirectory(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
entries.forEach(entry => {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
processDirectory(fullPath);
} else if (entry.isFile() && entry.name.endsWith(".mdx")) {
processFile(fullPath);
}
});
}
function processFile(filePath) {
let content = fs.readFileSync(filePath, "utf8");
// Regex che prende i Card con href YouTube
const regex = /<Card\s+[^>]*href="(https:\/\/(?:youtu\.be\/|www\.youtube\.com\/watch\?v=)([^"]+))"[^>]*><\/Card>/g;
content = content.replace(regex, (match, url, videoId) => {
let finalId = videoId;
// Se è un link watch?v=, estrai id
if (url.includes("watch?v=")) {
const params = new URLSearchParams(url.split("?")[1]);
finalId = params.get("v");
}
const embedUrl = `https://www.youtube.com/embed/${finalId}`;
return `<Frame>
<iframe
className="w-full aspect-video rounded-xl"
src="${embedUrl}"
title="YouTube video player"
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
</Frame>`;
});
fs.writeFileSync(filePath, content, "utf8");
console.log(`Processed: ${filePath}`);
}
processDirectory(dir);