Skip to content

Commit

Permalink
optimize getNumberOfCourses, monaco-editor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaByte committed Jan 16, 2024
1 parent 07b5e1a commit e4eb812
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion routes/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function CoursePage(
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/split.js/1.1.1/split.min.js">
</script>
<script src="/moaco.js"></script>
<script src="/monaco.js"></script>
<script src="/resizer.js" />
</Head>
<main>
Expand Down
2 changes: 1 addition & 1 deletion static/moaco.js → static/monaco.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ require.config({
});

require(["vs/editor/editor.main"], () => {
document.getElementById("editor-loading").style.display = "none";
const isNord = localStorage.getItem("selectedTheme") === "nord";
const vsTheme = isNord ? "vs-light" : "vs-dark";
window.editor = monaco.editor.create(document.getElementById("editor"), {
Expand All @@ -16,4 +15,5 @@ require(["vs/editor/editor.main"], () => {
setInterval(() => {
editor.layout();
}, 10);
document.getElementById("editor-loading").style.display = "none";
});
16 changes: 6 additions & 10 deletions utils/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { extract } from "https://deno.land/[email protected]/encoding/front_matter.ts"

import { Course, CourseAttributes, CourseGroup } from "../utils/types.ts";

export let CoursesCount = 0;

export async function getGroupJsonData(
groupPath: string,
): Promise<{ order: number; label: string; lableSlug: string } | undefined> {
Expand Down Expand Up @@ -66,6 +68,7 @@ export async function getCourses(
const slug = groupFile.name.replace(".md", "");
const coursePromise = getCourse(join(groupSlug, slug));
groupPromises.push(coursePromise);
CoursesCount++;
}
}

Expand All @@ -86,6 +89,7 @@ export async function getCourses(
} else if (file.name.endsWith(".md")) {
const slug = file.name.replace(".md", "");
nonGroupPromises.push(getCourse(slug));
CoursesCount++;
}
}

Expand All @@ -105,13 +109,5 @@ export async function getCourses(
}

export function getNumberOfCourses(courses: (Course | CourseGroup)[]) {
let count = 0;
for (const course of courses) {
if ("courses" in course) {
count += course.courses.length;
} else {
count++;
}
}
return count;
}
return CoursesCount;
}

0 comments on commit e4eb812

Please sign in to comment.