import { VideoDescription } from "./main.ts";
export const SMALL_WORDS = new Set([
"a",
"an",
"and",
"as",
"at",
"because",
"but",
"by",
"en",
"for",
"if",
"in",
"neither",
"nor",
"of",
"on",
"only",
"or",
"over",
"per",
"so",
"some",
"than",
"that",
"the",
"to",
"up",
"upon",
"v",
"versus",
"via",
"vs",
"when",
"with",
"without",
"yet",
]);
function capitalize(word: string): string {
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
}
function camelToTitleCase(camelCaseStr: string): string {
// Insert a space before each uppercase letter
const titleCaseStr = camelCaseStr.replace(/([A-Z])/g, ' $1');
// Split the string into words and process each word using map
const words = titleCaseStr.split(' ')
.map(v => v.toLowerCase())
.map(word => {
if (SMALL_WORDS.has(word)) {
return word;
}
return capitalize(word)
});
return capitalize(words.join(' '));
}
export function singleVideoDescription(video: VideoDescription): string {
const teachersList = video.teachers.map(v => "[[" + v + "]]").join(" & ");
const nagElement = video.nags.length > 0 ? `🔴` : "";
return `=== ${camelToTitleCase(video.title)} ===
Date: {{#time: Y-m-d (D) | ${video.date}}} ${nagElement}
Teachers: ${teachersList}
Level: ${video.level}
[[${video.path}|left|400px|thumb|${video.title}]]