mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 18:18:27 -05:00
chore: detuplication (#50955)
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -47,12 +47,12 @@ interface InsertOptions {
|
||||
function insertStepIntoMeta({ stepNum, stepId }: InsertOptions): void {
|
||||
const existingMeta = getMetaData();
|
||||
const oldOrder = [...existingMeta.challengeOrder];
|
||||
oldOrder.splice(stepNum - 1, 0, [stepId.toString()]);
|
||||
oldOrder.splice(stepNum - 1, 0, { id: stepId.toString(), title: '' });
|
||||
// rename all the files in challengeOrder
|
||||
const challengeOrder = oldOrder.map(([id], index) => [
|
||||
const challengeOrder = oldOrder.map(({ id }, index) => ({
|
||||
id,
|
||||
`Step ${index + 1}`
|
||||
]);
|
||||
title: `Step ${index + 1}`
|
||||
}));
|
||||
|
||||
updateMetaData({ ...existingMeta, challengeOrder });
|
||||
}
|
||||
@@ -62,10 +62,10 @@ function deleteStepFromMeta({ stepNum }: { stepNum: number }): void {
|
||||
const oldOrder = [...existingMeta.challengeOrder];
|
||||
oldOrder.splice(stepNum - 1, 1);
|
||||
// rename all the files in challengeOrder
|
||||
const challengeOrder = oldOrder.map(([id], index) => [
|
||||
const challengeOrder = oldOrder.map(({ id }, index) => ({
|
||||
id,
|
||||
`Step ${index + 1}`
|
||||
]);
|
||||
title: `Step ${index + 1}`
|
||||
}));
|
||||
|
||||
updateMetaData({ ...existingMeta, challengeOrder });
|
||||
}
|
||||
@@ -84,8 +84,7 @@ const updateStepTitles = (): void => {
|
||||
const filePath = `${getProjectPath()}${fileName}`;
|
||||
const frontMatter = matter.read(filePath);
|
||||
const newStepNum =
|
||||
meta.challengeOrder.findIndex(elem => elem[0] === frontMatter.data.id) +
|
||||
1;
|
||||
meta.challengeOrder.findIndex(({ id }) => id === frontMatter.data.id) + 1;
|
||||
const title = `Step ${newStepNum}`;
|
||||
const dashedName = `step-${newStepNum}`;
|
||||
const newData = {
|
||||
|
||||
Reference in New Issue
Block a user