|
|
@@ -10,7 +10,21 @@ const writeFileAsync = promisify(fs.writeFile);
|
|
|
|
|
|
// Source and destination paths
|
|
|
const markdownPath = path.resolve(__dirname, '../markdown');
|
|
|
-const jsonPath = path.resolve(__dirname, '../../front/src/resources/markdown.json');
|
|
|
+const jsonPath = path.resolve(__dirname, '../../back/public/dist/md-json');
|
|
|
+
|
|
|
+async function writeJson(tuto) {
|
|
|
+ // console.log(tuto.title, tuto.slug, tuto.items.map(({ title }) => title));
|
|
|
+ const filePath = path.join(jsonPath, `${tuto.slug}.json`);
|
|
|
+ const json = JSON.stringify(tuto.items);
|
|
|
+ return writeFileAsync(filePath, json);
|
|
|
+}
|
|
|
+
|
|
|
+async function writeJsonIndex(tutos) {
|
|
|
+ const filePath = path.join(jsonPath, 'index.json');
|
|
|
+ const index = tutos.map(({ title, slug }) => ({ title, slug }));
|
|
|
+ const json = JSON.stringify(index);
|
|
|
+ return writeFileAsync(filePath, json);
|
|
|
+}
|
|
|
|
|
|
async function run(filterFunc) {
|
|
|
const allFiles = await readdirAsync(markdownPath);
|
|
|
@@ -27,8 +41,9 @@ async function run(filterFunc) {
|
|
|
}
|
|
|
});
|
|
|
const tutos = await Promise.all(promises);
|
|
|
- const json = JSON.stringify(tutos);
|
|
|
- await writeFileAsync(jsonPath, json);
|
|
|
+ const writePromises = tutos.map(writeJson);
|
|
|
+ writePromises.push(writeJsonIndex(tutos));
|
|
|
+ await Promise.all(writePromises);
|
|
|
process.exit();
|
|
|
}
|
|
|
|