= {
GET(_req, ctx) {
- const foundCourseGroup = cache.merged.find((c) => {
- return "courses" in c && c.courses.length > 0 &&
- c.order === parseInt(ctx.params.slug, 10);
- });
+ let foundCourseGroup: CourseGroup | Course | undefined = undefined;
+ const toFind = isNaN(parseInt(ctx.params.slug))
+ ? decodeURIComponent(ctx.params.slug)
+ : parseInt(ctx.params.slug);
+
+ console.log("toFind", toFind);
+ if (typeof toFind === "number") {
+ foundCourseGroup = cache.merged.find((c) => {
+ return "courses" in c && c.courses.length > 0 &&
+ c.order === toFind;
+ });
+ } else {
+ console.log("label", toFind);
+ foundCourseGroup = cache.merged.find((c) => {
+ return "courses" in c && c.courses.length > 0 &&
+ c.label === toFind;
+ });
+ }
+
if (!foundCourseGroup) return ctx.renderNotFound();
return ctx.render(foundCourseGroup as CourseGroup);
},
diff --git a/routes/index.tsx b/routes/index.tsx
index 425601a..e2dd586 100644
--- a/routes/index.tsx
+++ b/routes/index.tsx
@@ -41,7 +41,7 @@ export default function BlogIndexPage(
المحتوى
-
+
{merged.map((course, index) => {
// Group of courses
if ("courses" in course) {
@@ -63,7 +63,7 @@ export default function BlogIndexPage(
} else {
// Single course
return (
-
+
);
diff --git a/utils/course.ts b/utils/course.ts
index 41c0ea2..8eb4f43 100644
--- a/utils/course.ts
+++ b/utils/course.ts
@@ -21,7 +21,7 @@ export async function getGroupOrder(
export async function getCourse(
slug: string,
-): Promise
{
+): Promise {
const text = await Deno.readTextFile(join("./courses", `${slug}.md`));
const { attrs, body } = extract(text);
const courseAttrs = attrs as CourseAttributes;
@@ -35,6 +35,14 @@ export async function getCourse(
return course;
}
+export async function getJson(
+ slug: string,
+): Promise {
+ const text = await Deno.readTextFile(join("./courses", `${slug}/_data.json`));
+ const json: { label: string } = JSON.parse(text);
+ return json.label;
+}
+
export async function getCourses(
cache: { merged: (Course | CourseGroup)[] } = { merged: [] },
): Promise<