better lecture ui

This commit is contained in:
2024-11-01 20:09:27 -06:00
parent bd8c9140eb
commit 48fc05d010
10 changed files with 156 additions and 26 deletions

View File

@@ -3,6 +3,7 @@ import path from "path";
import { basePath } from "./utils/fileSystemUtils";
import fs from "fs/promises";
import {
getLectureWeekName,
lectureFolderName,
lectureToString,
parseLecture,
@@ -51,19 +52,12 @@ export async function updateLecture(
lecture: Lecture
) {
const courseLectureRoot = path.join(basePath, courseName, lectureFolderName);
const startDate = getDateFromStringOrThrow(
courseSettings.startDate,
"semester start date in update lecture"
);
const lectureDate = getDateFromStringOrThrow(
lecture.date,
"lecture start date in update lecture"
);
const weekNumber = getWeekNumber(startDate, lectureDate)
.toString()
.padStart(2, "0");
const weekFolderName = `week-${weekNumber}`;
const weekFolderName = getLectureWeekName(courseSettings.startDate, lecture.date);
const weekPath = path.join(courseLectureRoot, weekFolderName);
if (!(await directoryExists(weekPath))) {
await fs.mkdir(weekPath, { recursive: true });

View File

@@ -1,5 +1,7 @@
import { getWeekNumber } from "@/app/course/[courseName]/calendar/calendarMonthUtils";
import { extractLabelValue } from "@/models/local/assignment/utils/markdownUtils";
import { Lecture } from "@/models/local/lecture";
import { getDateFromStringOrThrow } from "@/models/local/timeUtils";
export function parseLecture(fileContent: string): Lecture {
try {
@@ -27,4 +29,21 @@ Date: ${lecture.date}
${lecture.content}`;
}
export const lectureFolderName = "00 - lectures"
export const lectureFolderName = "00 - lectures";
export function getLectureWeekName(semesterStart: string, lectureDate: string) {
const startDate = getDateFromStringOrThrow(
semesterStart,
"semester start date in update lecture"
);
const targetDate = getDateFromStringOrThrow(
lectureDate,
"lecture start date in update lecture"
);
const weekNumber = getWeekNumber(startDate, targetDate)
.toString()
.padStart(2, "0");
const weekName = `week-${weekNumber}`;
return weekName;
}

View File

@@ -21,6 +21,9 @@ export function getLectureUrl(courseName: string, lectureDate: string) {
encodeURIComponent(lectureDate)
);
}
export function getLecturePreviewUrl(courseName: string, lectureDate: string) {
return getLectureUrl(courseName, lectureDate) + "/preview";
}
export function getCourseUrl(courseName: string) {
return "/course/" + encodeURIComponent(courseName);