fix(tools): use dashed name for live version of challenge in editor (#59401)

This commit is contained in:
Anna 2025-03-25 04:17:25 -04:00 committed by GitHub
parent 2e452761a6
commit aeeae20c97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View File

@ -7,11 +7,11 @@ export const getStepContent = async (
sup: string,
block: string,
step: string
): Promise<{ name: string; fileData: string }> => {
): Promise<{ name: string; dashedName: string; fileData: string }> => {
const filePath = join(CHALLENGE_DIR, sup, block, step);
const fileData = await readFile(filePath, 'utf8');
const name = matter(fileData).data.title as string;
return { name, fileData };
const dashedName = matter(fileData).data.dashedName as string;
return { name, dashedName, fileData };
};

View File

@ -1,4 +1,5 @@
export interface ChallengeContent {
name: string;
fileData: string;
dashedName: string;
}

View File

@ -20,6 +20,7 @@ const Editor = () => {
const [loading, setLoading] = useState(false);
const [items, setItems] = useState({
name: '',
dashedName: '',
fileData: ''
});
const [stepContent, setStepContent] = useState('');
@ -90,7 +91,9 @@ const Editor = () => {
</p>
<p>
<Link
to={`${import.meta.env.CHALLENGE_EDITOR_LEARN_CLIENT_LOCATION}/learn/${superBlockNameMap[superblock || '']}/${block || ''}/${items.name.replace(/[\s]+/g, '-').toLowerCase() || ''}`}
to={`${import.meta.env.CHALLENGE_EDITOR_LEARN_CLIENT_LOCATION}/learn/${superBlockNameMap[superblock || '']}/${block || ''}/${
items.dashedName
}`}
target='_blank'
>
View Live Version of the Challenge in your running development