Make jsonToArray iterate over every child in the json to read every folder in the repo

pull/21/head
Brogan Clements 2022-04-22 01:02:17 -04:00
parent ffa69c1429
commit fefe7b5b42
1 changed files with 23 additions and 21 deletions

View File

@ -21,37 +21,39 @@ function jsonToArray(json) {
// list of all topics (sections) // list of all topics (sections)
let sections = []; let sections = [];
// for each markdown document // for each markdown document
json.children[0].children.forEach((document) => { for (let i = 0; i < json.children.length; i++) {
// for each topic in the markdown json.children[i].children.forEach((document) => {
// these are typically h2 and h3 tags in the markdown // for each topic in the markdown
document.sections.forEach((section) => { // these are typically h2 and h3 tags in the markdown
// Add section to master list if it's not there document.sections.forEach((section) => {
if (!sections.includes(section.section)) sections.push(section.section); // Add section to master list if it's not there
// Add new entries that were under an h2 tag if (!sections.includes(section.section)) sections.push(section.section);
section.entries.forEach((entry) => { // Add new entries that were under an h2 tag
arr.push({ section.entries.forEach((entry) => {
author: entry.author,
title: entry.title,
url: entry.url,
lang: document.language,
section: section.section,
});
});
// Add new entries that were under an h3 tag
section.subsections.forEach((subsection) => {
subsection.entries.forEach((entry) => {
arr.push({ arr.push({
author: entry.author, author: entry.author,
title: entry.title, title: entry.title,
url: entry.url, url: entry.url,
lang: document.language, lang: document.language,
section: section.section, section: section.section,
subsection: subsection.section, });
});
// Add new entries that were under an h3 tag
section.subsections.forEach((subsection) => {
subsection.entries.forEach((entry) => {
arr.push({
author: entry.author,
title: entry.title,
url: entry.url,
lang: document.language,
section: section.section,
subsection: subsection.section,
});
}); });
}); });
}); });
}); });
}); }
return { arr: arr, sections: sections }; return { arr: arr, sections: sections };
} }