SPB Git

Repository Public

labels.ts 2.6 KB 45 lines typescript

1import type { CourseView, SessionView } from "@/modules/content-schema";23/** Exact instructor credit, built from the manifest (single source of truth: the course repository). */4export function credit(author: CourseView["author"]): string {5  return `${author.name} — ${author.role}, ${author.department}, ${author.institution}`;6}78export const pad2 = (n: number) => String(n).padStart(2, "0");9export const LEVEL_RANK: Record<SessionView["level"], number> = { "débutant": 1, "intermédiaire": 2, "avancé": 3 };10export const LEVEL_LABEL: Record<SessionView["level"], string> = { "débutant": "Débutant", "intermédiaire": "Intermédiaire", "avancé": "Avancé" };1112export function accessLabel(s: Pick<SessionView, "access" | "previewOnly"> & { slidesOnly?: boolean }): string {13  if (s.access === "archived") return "Archivée";14  if (s.access === "upcoming") return "À venir";15  if (s.previewOnly) return "Aperçu — non publiée";16  return s.slidesOnly ? "Diapositives en ligne" : "Publiée";17}1819/** What an open session offers today and what is still to come, in plain words: « Diapositives en ligne », « Vidéos à venir »… */20export function offerOf(s: Pick<SessionView, "sections" | "capsules">): { label: string; online: boolean }[] {21  return [22    { label: s.sections.slides ? "Diapositives en ligne" : "Diapositives à venir", online: Boolean(s.sections.slides) },23    { label: s.capsules.length ? (s.capsules.length > 1 ? `${s.capsules.length} vidéos en ligne` : "Vidéo en ligne") : "Vidéos à venir", online: s.capsules.length > 0 },24    { label: s.sections.quiz ? "Quiz en ligne" : "Quiz à venir", online: Boolean(s.sections.quiz) },25    { label: s.sections.lab ? "Laboratoire en ligne" : "Laboratoire à venir", online: Boolean(s.sections.lab) },26  ];27}2829export const partOf = (course: CourseView, s: Pick<SessionView, "part">) => course.parts.find((p) => p.id === s.part)!;3031/** « 55 à 65 min » */32export const range = ([a, b]: [number, number]) => (a === b ? `${a} min` : `${a} à ${b} min`);3334export function totalEffort(e: NonNullable<SessionView["effortMinutes"]>): string {35  const lo = Object.values(e).reduce((n, r) => n + r[0], 0), hi = Object.values(e).reduce((n, r) => n + r[1], 0);36  const h = (m: number) => (m >= 60 ? `${Math.floor(m / 60)} h${m % 60 ? ` ${pad2(m % 60)}` : ""}` : `${m} min`);37  return lo === hi ? h(lo) : `${h(lo)} à ${h(hi)}`;38}3940export const EFFORT_LABEL: Record<string, string> = { presentation: "Présentation", lab: "Laboratoire", quiz: "Quiz" };4142export function plural(n: number, one: string, many: string): string {43  return `${n} ${n > 1 ? many : one}`;44}45
Files main
Menu

Theme