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 Sep 2, 2024
1 parent 4ccc15a commit 1af25ec
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions src/utils/local-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,14 @@ Object.entries(allModels).forEach(([modelName, model]) => {

function isRefField(modelName: string, fieldName: string) {
return !!allReferenceFields[modelName + ':' + fieldName];
}
}p

const supportedFileTypes = ['md', 'json'];
function contentFilesInPath(dir: string) {
const globPattern = `${dir}/**/*.{${supportedFileTypes.join(',')}}`;
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 1af25ec

Please sign in to comment.