Added title casing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.env
|
.env
|
||||||
|
cov_profile/
|
||||||
|
|||||||
8
main.ts
8
main.ts
@@ -37,9 +37,11 @@ async function fetchPages(pages: string[], bot: Mwn): Promise<VideoDescription[]
|
|||||||
parseSummary(await new bot.Page(v).text(), v)
|
parseSummary(await new bot.Page(v).text(), v)
|
||||||
))
|
))
|
||||||
|
|
||||||
d.map((v, index) => ({ r: v, source: pages[index] })).filter((v): v is { source: string, r: PromiseRejectedResult } => v.r.status === "rejected").forEach(
|
d.map((v, index) => ({ r: v, source: pages[index] }))
|
||||||
v => console.warn(`Error parsing ${v.source}: ${v.r.reason}`
|
.filter((v): v is { source: string, r: PromiseRejectedResult } => v.r.status === "rejected")
|
||||||
))
|
.forEach(
|
||||||
|
v => console.warn(`Error parsing ${v.source}: ${v.r.reason}`
|
||||||
|
))
|
||||||
|
|
||||||
return d.filter(v => v.status === "fulfilled").map(v => v.value)
|
return d.filter(v => v.status === "fulfilled").map(v => v.value)
|
||||||
|
|
||||||
|
|||||||
2
run.sh
2
run.sh
@@ -1 +1 @@
|
|||||||
deno run --env-file=.env --allow-read=./descriptions.json --allow-net=dancing.thasky.one:443 -E main.ts
|
deno run --env-file=.env --allow-net=dancing.thasky.one:443 -E main.ts
|
||||||
|
|||||||
91
write.ts
91
write.ts
@@ -1,10 +1,71 @@
|
|||||||
import { VideoDescription } from "./main.ts";
|
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 {
|
export function singleVideoDescription(video: VideoDescription): string {
|
||||||
const teachersList = video.teachers.map(v => "[[" + v + "]]").join(" & ");
|
const teachersList = video.teachers.map(v => "[[" + v + "]]").join(" & ");
|
||||||
|
|
||||||
const nagElement = video.nags.length > 0 ? `<span title="${video.nags.join("
")}">🔴</span>` : "";
|
const nagElement = video.nags.length > 0 ? `<span title="${video.nags.join("
")}">🔴</span>` : "";
|
||||||
return `=== ${video.title} ===
|
return `=== ${camelToTitleCase(video.title)} ===
|
||||||
Date: {{#time: Y-m-d (D) | ${video.date}}} ${nagElement}<br>
|
Date: {{#time: Y-m-d (D) | ${video.date}}} ${nagElement}<br>
|
||||||
Teachers: ${teachersList}<br>
|
Teachers: ${teachersList}<br>
|
||||||
Level: ${video.level}
|
Level: ${video.level}
|
||||||
@@ -38,21 +99,23 @@ export function writeSections(events: VideoDescription[][]): string {
|
|||||||
}).join("\n\n\n")
|
}).join("\n\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bucketEvents(events: VideoDescription[]): VideoDescription[][] {
|
/**
|
||||||
const buckets: Record<string, VideoDescription[]> = {}
|
*
|
||||||
for (const e of events) {
|
* @param videos
|
||||||
const tag = e.event + e.location + new Date(e.date).getFullYear().toString()
|
* @returns Bucket of videos for of each event, grouped by `name`, `location` and `year`
|
||||||
if (tag in buckets) {
|
*/
|
||||||
buckets[tag].push(e)
|
export function bucketEvents(videos: VideoDescription[]): VideoDescription[][] {
|
||||||
} else {
|
const buckets = Object.groupBy(videos, (video) => {
|
||||||
buckets[tag] = [e]
|
return `${video.event}${video.location}${new Date(video.date).getFullYear()}`;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.values(buckets)
|
})
|
||||||
.forEach(b =>
|
|
||||||
|
const sortedBuckets = Object.values(buckets)
|
||||||
|
.filter(v => v !== undefined)
|
||||||
|
.map(b =>
|
||||||
b.sort((a, b) =>
|
b.sort((a, b) =>
|
||||||
new Date(a.date).getTime() - new Date(b.date).getTime()))
|
new Date(a.date).getTime() - new Date(b.date).getTime()))
|
||||||
|
|
||||||
return Object.values(buckets).sort((a, b) => new Date(a[0].date).getTime() - new Date(b[0].date).getTime())
|
return sortedBuckets
|
||||||
|
.sort((a, b) => new Date(a[0].date).getTime() - new Date(b[0].date).getTime())
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user