@@ -139,13 +139,35 @@ export const getAllFiles = function (dirPath, arrayOfFiles) {
139 return arrayOfFiles;
139 return arrayOfFiles;
142+function get(obj, path, defaultValue) {
143+ for (const index of path) {
144+ if (obj[index] === undefined) {
145+ return defaultValue;
152+function set(obj, path, value) {
154+ for (let i = 0; i < path.length - 1; i++) {
155+ if (piece[path[i]] === undefined) {
156+ piece[path[i]] = typeof path[i + 1] === "number" ? [] : {};
158+ piece = piece[path[i]];
160+ piece[path[path.length - 1]] = value;
142export function getLinksinSubdirs(path) {
164export function getLinksinSubdirs(path) {
143 const allFiles = getAllFiles(path);
165 const allFiles = getAllFiles(path);
144 const fileTree = {};
166 const fileTree = {};
145 allFiles.forEach((e) => {
167 allFiles.forEach((e) => {
146 const parsed = parse(e.substr(e.indexOf("content/") + 7));
168 const parsed = parse(e.substr(e.indexOf("content/") + 7));
147−
169+ const keys = parsed.dir.split("/").filter((e) => e !== "");
148− if (!(parsed.dir in fileTree)) {
170+ if (!get(fileTree, keys, false)) {
149 const fullPathofDir = join(
171 const fullPathofDir = join(
150 process.cwd(),
172 process.cwd(),
151 "/content",
173 "/content",
@@ -154,15 +176,15 @@ export function getLinksinSubdirs(path) {
155 const dirContents = fs.readFileSync(fullPathofDir, "utf8");
177 const dirContents = fs.readFileSync(fullPathofDir, "utf8");
156 const { data: dirData } = matter(dirContents, options);
178 const { data: dirData } = matter(dirContents, options);
157− fileTree[parsed.dir] = { name: dirData.title, pages: [] };
179+ set(fileTree, keys, { title: dirData.title, pages: [] });
160 const fileContents = fs.readFileSync(e, "utf8");
181 const fileContents = fs.readFileSync(e, "utf8");
161 const { data } = matter(fileContents, options);
182 const { data } = matter(fileContents, options);
162− fileTree[parsed.dir].pages.push({
183+ get(fileTree, keys, false).pages.push({
163− name: data.title,
184+ title: data.title,
164 base: parsed.base,
185 base: parsed.base,
165 slug: parsed.name,
186 slug: parsed.name,
187+ weight: data?.weight ?? 0,
168 return fileTree;
190 return fileTree;