feat: finalize academy redesign and production readiness
Align admin, community, search, library, learning and course management with the mockup. Add saved courses, download history, public community feed, instructor directory, backend search, course views, admin content tools and community moderation. Harden API and Nginx for production.
This commit is contained in:
50
lib/format.ts
Normal file
50
lib/format.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Course, Lesson } from '../types';
|
||||
|
||||
export const initials = (name: string) => name
|
||||
.split(/\s+/)
|
||||
.filter(Boolean)
|
||||
.map((word) => word[0])
|
||||
.slice(0, 2)
|
||||
.join('')
|
||||
.toUpperCase();
|
||||
|
||||
export const plural = (count: number, one: string, many: string) => `${count} ${count === 1 ? one : many}`;
|
||||
|
||||
export const lessonCount = (course: Course) => plural(course.lessons.length, 'aula', 'aulas');
|
||||
|
||||
/** "6 aulas · 3h 45min", omitting the duration while videos are still processing. */
|
||||
export const courseMeta = (course: Course) => {
|
||||
const parts = [lessonCount(course)];
|
||||
if (course.duration && course.duration !== '—' && course.duration !== 'Processando') parts.push(course.duration);
|
||||
return parts.join(' · ');
|
||||
};
|
||||
|
||||
export const lessonDuration = (lesson: Lesson) => (lesson.duration && lesson.duration !== '—' ? lesson.duration : '');
|
||||
|
||||
const parseMinutes = (duration: string) => {
|
||||
const hours = Number(/(\d+)h/.exec(duration)?.[1] || 0);
|
||||
const minutes = Number(/(\d+)\s*min/.exec(duration)?.[1] || 0);
|
||||
return hours * 60 + minutes;
|
||||
};
|
||||
|
||||
export const formatMinutes = (total: number) => {
|
||||
const hours = Math.floor(total / 60);
|
||||
const rest = total % 60;
|
||||
if (!hours) return `${rest}min`;
|
||||
return rest ? `${hours}h ${String(rest).padStart(2, '0')}min` : `${hours}h`;
|
||||
};
|
||||
|
||||
export const totalDuration = (courses: Course[]) => {
|
||||
const minutes = courses.reduce((sum, course) => sum + parseMinutes(course.duration || ''), 0);
|
||||
return minutes ? formatMinutes(minutes) : '';
|
||||
};
|
||||
|
||||
export const shortDate = (value?: string | null) => {
|
||||
if (!value) return '';
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return '';
|
||||
const months = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez'];
|
||||
return `${date.getDate()} ${months[date.getMonth()]}`;
|
||||
};
|
||||
|
||||
export const hasRealCover = (source?: string | null) => Boolean(source && !source.endsWith('/course-placeholder.svg'));
|
||||
Reference in New Issue
Block a user