Skip to content

Commit

Permalink
fix outline.json not found
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Jul 6, 2024
1 parent a90126b commit b887bd5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
13 changes: 3 additions & 10 deletions lib/contentManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { contentFolderName, instructionsFileName } from "./contentVariables";
import { ContentOutline } from "./types";

import outline from "@/content/outline.json";
Expand Down Expand Up @@ -37,19 +38,11 @@ The content folder follows this structure:
*/

export default class ContentManager {
public contentFolderPath: string = "./content";
public contentFolderName: string = this.contentFolderPath.replace("./", "");

public outlineJSONPath: string = "./content/outline.json";

public indexFileName = "index.mdx";
public instructionsFileName = "instructions.mdx";
public codeFileName = "code.ts";
public pathPrefix = "content";

public getOutline() {
// check if outline.json exists

return outline as ContentOutline;
}

Expand Down Expand Up @@ -109,10 +102,10 @@ export default class ContentManager {
return this.getOutline()[chapterIndex].steps.length;
}
public getInstructionsFilePath(urlPath: string) {
return `${this.contentFolderName}/${urlPath}/${this.instructionsFileName}`;
return `${contentFolderName}/${urlPath}/${instructionsFileName}`;
}
public getCodeFilePath(urlPath: string) {
return `${this.contentFolderName}/${urlPath}/${this.codeFileName}`;
return `${contentFolderName}/${urlPath}/${this.codeFileName}`;
}

public getPageMeta(urlPath: string) {
Expand Down
4 changes: 4 additions & 0 deletions lib/contentVariables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const contentFolderPath: string = "./content";
export const contentFolderName: string = contentFolderPath.replace("./", "");
export const indexFileName = "index.mdx";
export const instructionsFileName = "instructions.mdx";
20 changes: 12 additions & 8 deletions scripts/generateOutline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import fs from "fs";
import { contentManager } from "@/lib/contentManager";

import { Chapter, ContentOutline, Metadata } from "@/lib/types";
import matter from "gray-matter";
import {
contentFolderName,
contentFolderPath,
indexFileName,
instructionsFileName,
} from "@/lib/contentVariables";

function parseMdxMetadata(fullFilePath: string) {
const file = fs.readFileSync(fullFilePath, "utf-8");
Expand All @@ -13,31 +19,29 @@ function parseMdxMetadata(fullFilePath: string) {

function generateOutline(): ContentOutline {
const contentOutline: ContentOutline = [];
const files = fs.readdirSync(contentManager.contentFolderPath, {
const files = fs.readdirSync(contentFolderPath, {
withFileTypes: true,
});

files.forEach((file, chapterNumber) => {
if (file.isDirectory()) {
const { metadata } = parseMdxMetadata(
`${contentManager.contentFolderName}/${file.name}/${contentManager.indexFileName}`
`${contentFolderName}/${file.name}/${indexFileName}`
);

const chapter: Chapter = {
title: metadata.title,
folderName: file.name,
steps: [],
};
const chapterPath = `${contentManager.contentFolderPath}/${file.name}`;
const chapterPath = `${contentFolderPath}/${file.name}`;
let chapterFiles = fs.readdirSync(chapterPath, {
withFileTypes: true,
});
chapterFiles = chapterFiles.filter(
(file) => file.name !== contentManager.indexFileName
);
chapterFiles = chapterFiles.filter((file) => file.name !== indexFileName);
chapterFiles.forEach((chapterFile, stepNumber) => {
const { metadata } = parseMdxMetadata(
`${contentManager.contentFolderName}/${file.name}/${chapterFile.name}/${contentManager.instructionsFileName}`
`${contentFolderName}/${file.name}/${chapterFile.name}/${instructionsFileName}`
);

const step = {
Expand Down

0 comments on commit b887bd5

Please sign in to comment.