-
Notifications
You must be signed in to change notification settings - Fork 1
/
modify-content-json.ts
37 lines (32 loc) · 1.38 KB
/
modify-content-json.ts
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
import {addBookIdIfNoneExists, addChapterTitleIfNonePresent} from "./strapi-scripts/content-helpers";
// TOOD modify folder name from strapi-scripts to content-scripts
import {addUidAndBookIdIfNonePreset} from "./strapi-scripts/content-helpers";
const razrooMarkdownEngine = require('@razroo/razroo-markdown-engine').resolveMarkdownFile;
const mkdirp = require('mkdirp')
const contentJsonName = './content.json';
const contentJson = require(contentJsonName);
const articlesJsonName = './articles.json';
const articlesJson = require(articlesJsonName);
const fs = require('fs');
let chapters = contentJson.chapters;
let articleFiles = articlesJson
// addBookIdIfNoneExists(contentJson, contentJsonName);
addUidAndBookIdIfNonePreset(chapters, contentJson, contentJsonName);
// addChapterTitleIfNonePresent(chapters, bookJson, bookJsonName);
try {
for (const articleFile of articleFiles.chapters as any) {
for (const [x, file] of Object.entries(chapters) as any) {
if (articleFile.path === chapters[x].path) {
chapters[x].UID = articleFile.UID;
chapters[x].article = true;
chapters[x].articleId = articleFile.id;
console.log(articleFile.path)
}
}
}
}
finally {
fs.writeFile(contentJsonName, JSON.stringify(contentJson, null, 2), function writeJSON(err) {
if (err) return console.log(err);
});
}