Skip to content

Commit

Permalink
Update local-content.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
moehami authored Oct 19, 2024
1 parent de2946c commit f0db885
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/utils/local-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>>(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;
Expand Down

0 comments on commit f0db885

Please sign in to comment.