Improved layout, added warnings to result page
This commit is contained in:
28
parse.ts
28
parse.ts
@@ -1,21 +1,22 @@
|
||||
import { Mwn } from "mwn";
|
||||
import { VideoDescription } from "./main.ts";
|
||||
|
||||
function parseTemplate(description: string): Record<string, string> {
|
||||
function parseTemplate(description: string): { warnings: string[] } & { [k: string]: string } {
|
||||
|
||||
const u = new (new Mwn().Wikitext)(description)
|
||||
const r = u.parseTemplates({
|
||||
namePredicate: (name) => name === "DanceWorkshopDescription",
|
||||
})
|
||||
const warnings = []
|
||||
if (r.length < 1) {
|
||||
throw new Error("Could not find DanceWorkshopDescription")
|
||||
}
|
||||
if (r.length > 1) {
|
||||
console.warn("More than one DanceWorkshopDescription template found")
|
||||
warnings.push("More than one DanceWorkshopDescription template found")
|
||||
}
|
||||
const p = r[0]
|
||||
const properties = p.parameters.map(v => ({ [v.name]: v.value }))
|
||||
return Object.assign({}, ...properties)
|
||||
return Object.assign({}, { warnings }, ...properties)
|
||||
}
|
||||
|
||||
function parseBlock(header: string, text: string): string {
|
||||
@@ -35,9 +36,10 @@ export function parseSummary(description: string, name: string): VideoDescriptio
|
||||
const properties = parseTemplate(description)
|
||||
|
||||
const b: Partial<VideoDescription> = {};
|
||||
b.nags = properties.warnings
|
||||
|
||||
if (Object.hasOwn(properties, 'teachers')) {
|
||||
console.warn(`Page ${name} has old template usage [contains 'teachers' key]`)
|
||||
b.nags.push(`Contains 'teachers' key instead of 'leader'/'follower'`)
|
||||
const t = properties['teachers'].split('&').map(item => item.trim());
|
||||
b.teachers = t
|
||||
} else {
|
||||
@@ -52,15 +54,25 @@ export function parseSummary(description: string, name: string): VideoDescriptio
|
||||
|
||||
|
||||
if (!Object.hasOwn(properties, 'patterns')) {
|
||||
console.warn(`Page ${name} has old template usage [no 'patterns' key]`)
|
||||
b.patterns = parseBlock("Shown Patterns", description)
|
||||
b.nags.push(`No 'patterns' key`)
|
||||
try {
|
||||
b.patterns = parseBlock("Shown Patterns", description)
|
||||
} catch (e) {
|
||||
b.nags.push("Shown Patterns: " + e)
|
||||
b.patterns = ""
|
||||
}
|
||||
} else {
|
||||
b.patterns = properties['patterns']
|
||||
}
|
||||
|
||||
if (!Object.hasOwn(properties, 'notes')) {
|
||||
console.warn(`Page ${name} has old template usage [no 'notes' key]`)
|
||||
b.notes = parseBlock("Notes", description)
|
||||
b.nags.push(`No 'notes' key`)
|
||||
try {
|
||||
b.notes = parseBlock("Notes", description)
|
||||
} catch (e) {
|
||||
b.nags.push("Notes: " + e)
|
||||
b.notes = ""
|
||||
}
|
||||
} else {
|
||||
b.notes = properties['notes']
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user