when creating assignments, verify the classroom url can be swapped

This commit is contained in:
2025-08-29 11:05:50 -06:00
parent 5f408749e4
commit 523a05d45e
3 changed files with 20 additions and 2 deletions

View File

@@ -17,3 +17,5 @@ courses:
name: Old Adv Frontend name: Old Adv Frontend
- path: ./1430/2025-spring-jonathan/Modules/ - path: ./1430/2025-spring-jonathan/Modules/
name: Jonathan UX name: Jonathan UX
- path: ./1400/2025_spring_alex/modules/
name: 1400-spring

View File

@@ -36,6 +36,7 @@ export const canvasAssignmentService = {
{ {
source: "insert_github_classroom_url", source: "insert_github_classroom_url",
destination: localAssignment.githubClassroomAssignmentShareLink || "", destination: localAssignment.githubClassroomAssignmentShareLink || "",
strict: true,
}, },
], ],
}); });
@@ -93,6 +94,7 @@ export const canvasAssignmentService = {
source: "insert_github_classroom_url", source: "insert_github_classroom_url",
destination: destination:
localAssignment.githubClassroomAssignmentShareLink || "", localAssignment.githubClassroomAssignmentShareLink || "",
strict: true,
}, },
], ],
}), }),

View File

@@ -87,11 +87,25 @@ export function markdownToHTMLSafe({
markdownString: string; markdownString: string;
settings: LocalCourseSettings; settings: LocalCourseSettings;
convertImages?: boolean; convertImages?: boolean;
replaceText?: { source: string; destination: string }[]; replaceText?: { source: string; destination: string; strict?: boolean }[];
}) { }) {
const html = markdownToHtmlNoImages(markdownString); const html = markdownToHtmlNoImages(markdownString);
const replacedHtml = replaceText.reduce( const replacedHtml = replaceText.reduce(
(acc, { source, destination }) => acc.replaceAll(source, destination), (acc, { source, destination, strict = false }) => {
if (strict) {
if (typeof destination === "undefined" || destination === null) {
throw new Error(
`Text replacement failed: destination is undefined for source "${source}"`
);
}
if (destination === "") {
throw new Error(
`Text replacement failed: destination is empty string for source "${source}"`
);
}
}
return acc.replaceAll(source, destination);
},
html html
); );