Made first version work
This commit is contained in:
52
write.ts
Normal file
52
write.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { VideoDescription } from "./main.ts";
|
||||
|
||||
export function singleVideoDescription(video: VideoDescription): string {
|
||||
const teachersList = video.teachers.map(v => "[[" + v + "]]").join(" & ");
|
||||
|
||||
return `=== ${video.title} ===
|
||||
Date:{{#time: Y-m-d (D) | ${video.date}}}<br>
|
||||
Teachers: ${teachersList}<br>
|
||||
Level: ${video.level}
|
||||
|
||||
[[${video.path}|left|400px|thumb|${video.title}]]
|
||||
|
||||
==== Shown Patterns ====
|
||||
${video.patterns}
|
||||
|
||||
==== Notes ====
|
||||
${video.notes}`;
|
||||
}
|
||||
|
||||
export function writeSection(events: VideoDescription[][]): string {
|
||||
return events.map(v => {
|
||||
const token = v[0]
|
||||
const event_name = token.event === token.location ? token.event : token.event + " " + token.location
|
||||
|
||||
// FIXME: This will break with videos in 75 years
|
||||
const event_date = event_name.match(/\d{2}|20\d{2}/) ? "" : new Date(token.date).getFullYear().toString()
|
||||
|
||||
let r = `== ${event_name} ${event_date} ==\n`
|
||||
r += `${v.length} Videos\n`
|
||||
r += v.map(video => singleVideoDescription(video)).join("\n\n")
|
||||
return r
|
||||
}).join("\n\n\n")
|
||||
}
|
||||
|
||||
export function bucketEvents(events: VideoDescription[]): VideoDescription[][] {
|
||||
const buckets: Record<string, VideoDescription[]> = {}
|
||||
for (const e of events) {
|
||||
const tag = e.event + e.location + new Date(e.date).getFullYear().toString()
|
||||
if (tag in buckets) {
|
||||
buckets[tag].push(e)
|
||||
} else {
|
||||
buckets[tag] = [e]
|
||||
}
|
||||
}
|
||||
|
||||
Object.values(buckets)
|
||||
.forEach(b =>
|
||||
b.sort((a, b) =>
|
||||
new Date(b.date).getTime() - new Date(a.date).getTime()))
|
||||
|
||||
return Object.values(buckets)
|
||||
}
|
||||
Reference in New Issue
Block a user