Fixed title casing
This commit is contained in:
2
main.ts
2
main.ts
@@ -120,9 +120,11 @@ async function main() {
|
||||
const relevantFiles = await getWorkshopVideos(bot)
|
||||
const { pages: d, errors: parseErrors } = await fetchPages(relevantFiles, bot)
|
||||
const t = writeSections(bucketEvents(d))
|
||||
|
||||
const trigger_summary = 'Triggered by changes to ' + paths.map(v => `[[${v}]]`).join(", ")
|
||||
const error_summary = parseErrors.join("\n")
|
||||
const summary = [trigger_summary, error_summary].filter(v => v !== undefined && v.length > 0).join("\n")
|
||||
|
||||
const response = await bot.save(title, "{{TOC|limit=3}}\n\n" + t, summary);
|
||||
console.log(response)
|
||||
})
|
||||
|
||||
1
parse.ts
1
parse.ts
@@ -79,5 +79,6 @@ export function parseSummary(description: string, name: string): VideoDescriptio
|
||||
b.path = name
|
||||
const titleMatch = name.match(/File:WCS \w+ (?<title>.+)\.[^.]+/)
|
||||
b.title = titleMatch?.groups ? titleMatch.groups['title'] : name
|
||||
b.title = b.title.trim()
|
||||
return (b as VideoDescription)
|
||||
}
|
||||
|
||||
57
util_string.ts
Normal file
57
util_string.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
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",
|
||||
]);
|
||||
|
||||
export function capitalize(word: string): string {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||
}
|
||||
|
||||
export function camelToTitleCase(camelCaseStr: string): string {
|
||||
const titleCaseStr = camelCaseStr.replace(/([A-Z])/g, ' $1');
|
||||
|
||||
const words = titleCaseStr.split(' ')
|
||||
.map(v => v.toLowerCase())
|
||||
.map(word => {
|
||||
if (SMALL_WORDS.has(word)) {
|
||||
return word;
|
||||
}
|
||||
return capitalize(word)
|
||||
});
|
||||
|
||||
return capitalize(words.join(' '));
|
||||
}
|
||||
12
util_string_test.ts
Normal file
12
util_string_test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { assertEquals } from "@std/assert/equals";
|
||||
import { camelToTitleCase } from "./util_string.ts";
|
||||
|
||||
Deno.test("camelToTitleCase transforms camelCase to Title Case", () => {
|
||||
assertEquals(camelToTitleCase("thisIsATest"), "This Is a Test");
|
||||
assertEquals(camelToTitleCase("denoIsAwesome"), "Deno Is Awesome");
|
||||
assertEquals(camelToTitleCase("helloWorld"), "Hello World");
|
||||
});
|
||||
|
||||
Deno.test("camelToTitleCase handles empty string", () => {
|
||||
assertEquals(camelToTitleCase(""), "");
|
||||
});
|
||||
60
write.ts
60
write.ts
@@ -1,65 +1,7 @@
|
||||
import { VideoDescription } from "./main.ts";
|
||||
import { camelToTitleCase } from "./util_string.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(" & ");
|
||||
|
||||
Reference in New Issue
Block a user