Skip to content

Commit 00ac6ce

Browse files
committed
refactor(courses): migrate instructor fields to use people collection references
- Updated `coursesCollection` schema in `src/content/config.ts` to type the `instructor` field as a `reference('people')`. - Modified all course markdown entries to use person slugs (e.g., `lale-akarun`, `berk-gokberk`) instead of hardcoded strings. - Refactored `courses.astro` and `courses/[slug].astro` templates to asynchronously resolve instructor references via `getEntry`. - Added a `shortenTitle` helper to automatically abbreviate academic titles (e.g., "Assistant Professor" to "Asst. Prof.") on course views.
1 parent 8dff547 commit 00ac6ce

7 files changed

Lines changed: 40 additions & 11 deletions

src/content/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineCollection, z } from 'astro:content';
1+
import { defineCollection, reference, z } from 'astro:content';
22

33
// Define the schema for the papers collection
44
const papersCollection = defineCollection({
@@ -91,7 +91,7 @@ const coursesCollection = defineCollection({
9191
schema: z.object({
9292
title: z.string(),
9393
code: z.string(),
94-
instructor: z.string(),
94+
instructor: reference('people'),
9595
description: z.string().optional(),
9696
semester: z.string().optional(),
9797
credits: z.number().optional(),

src/content/courses/cmpe537-computer-vision.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Computer Vision"
33
code: "CMPE 537"
44
description: "Graduate computer vision: imaging and cameras, filtering and CNNs, segmentation, features, object and action recognition, motion, tracking, and 3D vision—with implementations and a term project."
55
semester: "Fall 2025–2026"
6-
instructor: "Prof. Dr. Lale Akarun"
6+
instructor: "lale-akarun"
77
credits: 3
88
featured: true
99
---
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: "3D Computer Vision"
33
code: "CMPE 538"
4-
instructor: "Prof. Dr. Lale Akarun"
4+
instructor: "lale-akarun"
55
---
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
title: "Introduction to Biometrics"
33
code: "CMPE 58Z"
4-
instructor: "Prof. Dr. Berk Gökberk"
4+
instructor: "berk-gokberk"
55
---

src/content/courses/cmpe593-deep-learning-computer-vision.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Deep Learning for Computer Vision"
33
code: "CMPE 593"
44
description: "Graduate course on applied deep learning for computer vision: convolutional networks, detection, segmentation, generative models, and vision transformers."
55
semester: "Fall 2025–2026"
6-
instructor: "Prof. Dr. Berk Gökberk"
6+
instructor: "berk-gokberk"
77
credits: 3
88
syllabus: "https://registration.bogazici.edu.tr/scripts/instructor/coursedescriptions/2025-2026-1/CMPE59301.PDF"
99
featured: true

src/pages/courses.astro

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
---
22
import MainLayout from '../layouts/MainLayout.astro';
3-
import { getCollection } from 'astro:content';
3+
import { getCollection, getEntry } from 'astro:content';
44
55
const courses = await getCollection('courses');
66
courses.sort((a, b) => a.data.code.localeCompare(b.data.code));
7+
8+
const coursesWithInstructors = await Promise.all(
9+
courses.map(async (course) => {
10+
const instructor = await getEntry(course.data.instructor);
11+
return { ...course, instructorData: instructor?.data };
12+
})
13+
);
14+
15+
function shortenTitle(title?: string) {
16+
if (!title) return '';
17+
if (title === "Professor") return "Prof.";
18+
if (title === "Assistant Professor") return "Asst. Prof.";
19+
if (title === "Associate Professor") return "Assoc. Prof.";
20+
return title;
21+
}
22+
723
const base = import.meta.env.BASE_URL;
824
---
925

@@ -12,7 +28,7 @@ const base = import.meta.env.BASE_URL;
1228
<h1 class="text-4xl font-bold text-primary mb-12 text-center">Courses</h1>
1329

1430
<div class="max-w-2xl mx-auto space-y-4">
15-
{courses.map((course) => (
31+
{coursesWithInstructors.map((course) => (
1632
<div class="bg-white rounded-lg shadow-md px-6 py-4 flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3">
1733
<div class="min-w-0 flex-1">
1834
<span class="text-sm font-medium text-primary">{course.data.code}</span>
@@ -25,7 +41,9 @@ const base = import.meta.env.BASE_URL;
2541
<p class="text-sm text-gray-600 mt-2 leading-relaxed">{course.data.description}</p>
2642
)}
2743
</div>
28-
<p class="text-gray-600 sm:text-right sm:shrink-0">{course.data.instructor}</p>
44+
<p class="text-gray-600 sm:text-right sm:shrink-0">
45+
{course.instructorData ? `${shortenTitle(course.instructorData.title)} ${course.instructorData.name}` : ''}
46+
</p>
2947
</div>
3048
))}
3149
</div>

src/pages/courses/[slug].astro

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
import MainLayout from '../../layouts/MainLayout.astro';
3-
import { getCollection } from 'astro:content';
3+
import { getCollection, getEntry } from 'astro:content';
44
55
export async function getStaticPaths() {
66
const courses = await getCollection('courses');
@@ -11,6 +11,17 @@ export async function getStaticPaths() {
1111
}
1212
1313
const { course } = Astro.props;
14+
const instructor = await getEntry(course.data.instructor);
15+
const instructorData = instructor?.data;
16+
17+
function shortenTitle(title?: string) {
18+
if (!title) return '';
19+
if (title === "Professor") return "Prof.";
20+
if (title === "Assistant Professor") return "Asst. Prof.";
21+
if (title === "Associate Professor") return "Assoc. Prof.";
22+
return title;
23+
}
24+
1425
const { Content } = await course.render();
1526
const base = import.meta.env.BASE_URL;
1627
---
@@ -37,7 +48,7 @@ const base = import.meta.env.BASE_URL;
3748
</div>
3849

3950
<div class="mb-8">
40-
<p class="text-gray-600 mb-1"><span class="font-semibold">Instructor:</span> {course.data.instructor}</p>
51+
<p class="text-gray-600 mb-1"><span class="font-semibold">Instructor:</span> {instructorData ? `${shortenTitle(instructorData.title)} ${instructorData.name}` : ''}</p>
4152
{course.data.semester != null && course.data.semester !== '' && (
4253
<p class="text-gray-600 mb-1"><span class="font-semibold">Semester:</span> {course.data.semester}</p>
4354
)}

0 commit comments

Comments
 (0)