-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-paths.js
More file actions
52 lines (41 loc) · 1.43 KB
/
content-paths.js
File metadata and controls
52 lines (41 loc) · 1.43 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
const fs = require("fs");
const path = require("path");
// Function to get all file paths recursively
function getAllFilePaths(dir, fileList = []) {
if (!fs.existsSync(dir)) {
console.error(`Directory does not exist: ${dir}`);
return fileList;
}
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
fileList = getAllFilePaths(filePath, fileList);
} else {
// Only include .md files
if (filePath.endsWith(".md")) {
fileList.push(filePath);
}
}
});
return fileList;
}
// Define the content directory and the output file path
const contentDir = path.join(__dirname, "public", "content");
const outputFilePath = path.join(__dirname, "app", "content-paths.ts");
// Get all file paths
const filePaths = getAllFilePaths(contentDir);
// Convert absolute paths to relative paths from the content directory
const relativePaths = filePaths.map((filePath) =>
path.relative(contentDir, filePath).replace(/\\/g, "/")
);
// Generate the TypeScript content
const tsContent = `// This file is auto-generated
export const contentPaths = ${JSON.stringify(relativePaths, null, 2)};
`;
// Write the TypeScript content to the output file
fs.writeFileSync(outputFilePath, tsContent, "utf8");
console.log(
`${relativePaths.length} markdown files have been written to ${outputFilePath}`
);