mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 03:03:06 -05:00
* feat: add challenge editor tool chore: prepare API/Client setup feat: migrate to react! feat: styling fix: useEffect loop feat: add challenge helpers feat: use actual code editor feat: styling Bring it a bit more in line with /learn * refactor: use workspaces Which unfortunately required a rollback to React 16, because having multiple React versions causes all sorts of issues. * chore: apply Oliver's review suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: remove test files for now * fix: prettier issue * chore: apply oliver's review suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: move scripts to root * fix: lint errors oops * chore: remove reportWebVitals thing * chore: DRY out paths * fix: create-empty-steps takes one arg * chore: start doesn't make sense now * chore: DRY out button requests * chore: one more review suggestion Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: cleanup CRA files * fix: correct note for creating new project * feat: enable js and jsx highlighting * feat: include all superblocks * feat: improve button ux * feat: add "breadcrumbs" * feat: add link back to block from step tools * chore: remove unused deps * chore: apply oliver's review suggestions Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * chore: parity between file names and commands Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { readdir, readFile } from 'fs/promises';
|
|
import { join } from 'path';
|
|
|
|
import matter from 'gray-matter';
|
|
|
|
import { PartialMeta } from '../interfaces/PartialMeta';
|
|
import { CHALLENGE_DIR, META_DIR } from '../configs/paths';
|
|
|
|
const getFileOrder = (id: string, meta: PartialMeta) => {
|
|
return meta.challengeOrder.findIndex(([f]) => f === id);
|
|
};
|
|
|
|
export const getSteps = async (sup: string, block: string) => {
|
|
const filePath = join(CHALLENGE_DIR, sup, block);
|
|
|
|
const metaPath = join(META_DIR, block, 'meta.json');
|
|
|
|
const metaData = JSON.parse(await readFile(metaPath, 'utf8')) as PartialMeta;
|
|
|
|
const stepFilenames = await readdir(filePath);
|
|
const stepData = await Promise.all(
|
|
stepFilenames.map(async filename => {
|
|
const stepPath = join(filePath, filename);
|
|
const step = await readFile(stepPath, 'utf8');
|
|
const frontMatter = matter(step);
|
|
|
|
return {
|
|
name: frontMatter.data.title as string,
|
|
id: frontMatter.data.id as string,
|
|
path: filename
|
|
};
|
|
})
|
|
);
|
|
|
|
return stepData.sort(
|
|
(a, b) => getFileOrder(a.id, metaData) - getFileOrder(b.id, metaData)
|
|
);
|
|
};
|