mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-20 10:38:17 -05:00
refactor: share common intro creation code (#61814)
This commit is contained in:
committed by
GitHub
parent
91f87ea237
commit
0ae01847cb
@@ -12,6 +12,7 @@ import {
|
||||
} from '../../shared/config/curriculum';
|
||||
import { createDialogueFile, validateBlockName } from './utils';
|
||||
import { getBaseMeta } from './helpers/get-base-meta';
|
||||
import { createIntroMD } from './helpers/create-intro';
|
||||
|
||||
const helpCategories = ['English'] as const;
|
||||
|
||||
@@ -42,12 +43,12 @@ async function createLanguageBlock(
|
||||
if (!title) {
|
||||
title = block;
|
||||
}
|
||||
void updateIntroJson(superBlock, block, title);
|
||||
await updateIntroJson(superBlock, block, title);
|
||||
|
||||
const challengeId = await createDialogueChallenge(superBlock, block);
|
||||
void createMetaJson(superBlock, block, title, helpCategory, challengeId);
|
||||
await createMetaJson(superBlock, block, title, helpCategory, challengeId);
|
||||
// TODO: remove once we stop relying on markdown in the client.
|
||||
void createIntroMD(superBlock, block, title);
|
||||
await createIntroMD(superBlock, block, title);
|
||||
}
|
||||
|
||||
async function updateIntroJson(
|
||||
@@ -100,28 +101,6 @@ async function createMetaJson(
|
||||
);
|
||||
}
|
||||
|
||||
async function createIntroMD(superBlock: string, block: string, title: string) {
|
||||
const introMD = `---
|
||||
title: Introduction to the ${title}
|
||||
block: ${block}
|
||||
superBlock: ${superBlock}
|
||||
---
|
||||
|
||||
## Introduction to the ${title}
|
||||
|
||||
This page is for the ${title}
|
||||
`;
|
||||
const dirPath = path.resolve(
|
||||
__dirname,
|
||||
`../../client/src/pages/learn/${superBlock}/${block}/`
|
||||
);
|
||||
const filePath = path.resolve(dirPath, 'index.md');
|
||||
if (!existsSync(dirPath)) {
|
||||
await withTrace(fs.mkdir, dirPath);
|
||||
}
|
||||
void withTrace(fs.writeFile, filePath, introMD, { encoding: 'utf8' });
|
||||
}
|
||||
|
||||
async function createDialogueChallenge(
|
||||
superBlock: SuperBlocks,
|
||||
block: string
|
||||
|
||||
Reference in New Issue
Block a user