Files
freeCodeCamp/tools/challenge-editor/api/utils/get-step-contents.ts

18 lines
586 B
TypeScript

import { readFile } from 'fs/promises';
import { join } from 'path';
import matter from 'gray-matter';
import { CHALLENGE_DIR } from '../configs/paths';
export const getStepContent = async (
sup: string,
block: string,
step: string
): Promise<{ name: string; dashedName: string; fileData: string }> => {
const filePath = join(CHALLENGE_DIR, sup, block, step);
const fileData = await readFile(filePath, 'utf8');
const name = matter(fileData).data.title as string;
const dashedName = matter(fileData).data.dashedName as string;
return { name, dashedName, fileData };
};