Repository navigation
Expand file tree
/
Copy pathtoMarkdown.js
More file actions
109 lines (94 loc) · 2.16 KB
/
Copy pathtoMarkdown.js
File metadata and controls
109 lines (94 loc) · 2.16 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* /toLatex.js
*
* Author: Ben Siebert <hello@ben-siebert.de>
* Copyright: Copyright (c) 2018-2024 Ben Siebert. All rights reserved.
* License: Project License
* Created At: 12.06.2024
*
*/
const fs = require("fs");
const path = require("path");
const byteSize = require("byte-size");
const ignore = [
".turbo",
".git",
".idea",
".ico",
".jpg",
".jpeg",
".png",
".docusaurus",
".ttf",
".zip",
".afdesign",
"LICENSE",
".lock",
"package-lock.json",
".log",
"node_modules",
".next",
"dist",
"build",
".codeup_app_stats.json",
".react-email",
".env",
".env.web",
"pdf",
"docs",
"svg",
"codeup.tex",
".woff2",
"toMarkdown.js",
];
let paths = getAllPaths(".", []);
paths = paths.filter((p) => {
let allowed = true;
ignore.forEach((d) => {
if (p.toLowerCase().includes(d.toLowerCase())) {
allowed = false;
}
});
return allowed;
});
let title = `# CodeUp Quellcode
**Author:** Ben Siebert
**Generated At:** ${new Date().toLocaleString()}`;
let toc = `
# Inhaltsverzeichnis \n
`;
let markdown = ``;
for (let file of paths) {
file = file.replace(path.join(__dirname, "/"), "");
file = file.replace(/\\/g, "/");
console.log(`Reading ${file}`);
let content = fs.readFileSync(file, "utf8");
/*content = removeEmojis(content);
content = content.replace("[", "\\verb|[|");
content = content.replace("]", "\\verb|]|");*/
toc += `* [${file}](#${file}) - (${byteSize(content.length).toString()})\n`;
markdown += `## ${file} \n\n\`\`\`\n${content}\`\`\`\n\n\n`;
}
//markdown = markdown.replace(/\\/g, "\\\\");
markdown = markdown.replace(/[^\x00-\x7F]/g, ""); // remove non-ascii characters
fs.writeFileSync(
path.join(__dirname, "codeup.MD"),
`
${title}
${toc}
${markdown}
`
);
console.log("Done!");
function getAllPaths(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllPaths(dirPath + "/" + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
}
});
return arrayOfFiles;
}