mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 18:18:27 -05:00
refactor: share common intro creation code (#61814)
This commit is contained in:
committed by
GitHub
parent
91f87ea237
commit
0ae01847cb
36
tools/challenge-helper-scripts/helpers/create-intro.ts
Normal file
36
tools/challenge-helper-scripts/helpers/create-intro.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs/promises';
|
||||
|
||||
function introTemplate(
|
||||
superBlock: string,
|
||||
block: string,
|
||||
title: string
|
||||
): string {
|
||||
return `---
|
||||
title: Introduction to the ${title}
|
||||
block: ${block}
|
||||
superBlock: ${superBlock}
|
||||
---
|
||||
|
||||
## Introduction to the ${title}
|
||||
|
||||
This page is for the ${title}
|
||||
`;
|
||||
}
|
||||
|
||||
export async function createIntroMD(
|
||||
superBlock: string,
|
||||
block: string,
|
||||
title: string
|
||||
) {
|
||||
const dirPath = path.resolve(
|
||||
__dirname,
|
||||
`../../../client/src/pages/learn/${superBlock}/${block}/`
|
||||
);
|
||||
await fs.mkdir(dirPath, { recursive: true });
|
||||
|
||||
const filePath = path.resolve(dirPath, 'index.md');
|
||||
await fs.writeFile(filePath, introTemplate(superBlock, block, title), {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user