From f0db885abb10b10dd1d527b42154df08c2c40f82 Mon Sep 17 00:00:00 2001 From: moehami Date: Sat, 19 Oct 2024 10:43:14 +0300 Subject: [PATCH] Update local-content.ts --- src/utils/local-content.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/utils/local-content.ts b/src/utils/local-content.ts index cc18689..7aa3217 100644 --- a/src/utils/local-content.ts +++ b/src/utils/local-content.ts @@ -30,6 +30,32 @@ function contentFilesInPath(dir: string) { return globSync(globPattern); } +function readContent(file: string) { + const rawContent = fs.readFileSync(file, 'utf8'); + let content = null; + switch (path.extname(file).substring(1)) { + case 'md': + const parsedMd = frontmatter>(rawContent); + content = { + ...parsedMd.attributes, + markdown_content: parsedMd.body + }; + break; + case 'json': + content = JSON.parse(rawContent); + break; + default: + throw Error(`Unhandled file type: ${file}`); + } + + // Make Sourcebit-compatible + content.__metadata = { + id: file, + modelName: content.type + }; + + return content; +} function resolveReferences(content, fileToContent) { if (!content || !content.type) return;