feat: mark user editable regions in help post (#48512)

Co-authored-by: Naomi Carrigan <nhcarrigan@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Co-authored-by: kravmaguy <flex4lease@gmail.com>
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>

Closes https://github.com/freeCodeCamp/freeCodeCamp/issues/46411
This commit is contained in:
abe
2022-12-22 10:50:25 -05:00
committed by GitHub
parent e451a54d25
commit f3446daaae

View File

@@ -43,13 +43,36 @@ function createQuestionEpic(action$, state$, { window }) {
ofType(actionTypes.createQuestion),
tap(() => {
const state = state$.value;
const challengeFiles = challengeFilesSelector(state);
let challengeFiles = challengeFilesSelector(state);
const {
title: challengeTitle,
superBlock,
block,
helpCategory
} = challengeMetaSelector(state);
if (
challengeFiles?.some(file => file.editableRegionBoundaries.length > 0)
) {
const editableRegionStrings = fileExtension => {
const startComment = fileExtension === 'html' ? '<!--' : '/*';
const endComment = fileExtension === 'html' ? '-->' : '*/';
return `\n${startComment} User Editable Region ${endComment}\n`;
};
const filesWithEditableRegions = challengeFiles.map(file => {
const { contents, editableRegionBoundaries, ext } = file;
if (editableRegionBoundaries.length > 0) {
const comment = editableRegionStrings(ext);
const [start, end] = editableRegionBoundaries;
const lines = contents.split('\n');
lines.splice(start, 0, comment);
lines.splice(end, 0, comment);
return { ...file, contents: lines.join('\n') };
}
return file;
});
challengeFiles = filesWithEditableRegions;
}
const {
navigator: { userAgent },
location: { pathname, origin }