forked from hamcha/tghandbook
Update processing and add try-catch per page
This commit is contained in:
parent
df651c1f89
commit
1334c96aaa
5 changed files with 36 additions and 20 deletions
|
@ -18,22 +18,30 @@ export const PAGE_VERSIONS = {
|
|||
const MAX_WIDTH = 440;
|
||||
|
||||
export function processHTML(root: HTMLElement, docname: string): void {
|
||||
processGlobal(root, docname);
|
||||
try {
|
||||
processGlobal(root, docname);
|
||||
} catch (e) {
|
||||
console.error(`Error processing page: ${docname}`);
|
||||
}
|
||||
|
||||
switch (docname) {
|
||||
case "Guide_to_chemistry":
|
||||
processChemistry(root);
|
||||
break;
|
||||
case "Infections":
|
||||
processVirology(root);
|
||||
break;
|
||||
case "Guide_to_food":
|
||||
processFood(root);
|
||||
break;
|
||||
case "Guide_to_drinks":
|
||||
processDrinks(root);
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
switch (docname) {
|
||||
case "Guide_to_chemistry":
|
||||
processChemistry(root);
|
||||
break;
|
||||
case "Infections":
|
||||
processVirology(root);
|
||||
break;
|
||||
case "Guide_to_food":
|
||||
processFood(root);
|
||||
break;
|
||||
case "Guide_to_drinks":
|
||||
processDrinks(root);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error processing page: ${docname} (specific enhancements)`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -204,11 +204,11 @@ export function chemistryScript(root: HTMLElement): void {
|
|||
);
|
||||
|
||||
registerSearchEntries(
|
||||
el.map((element, id) => ({
|
||||
Array.from(root.querySelectorAll<HTMLElement>("table.wikitable > tbody > tr:not(:first-child) th .reagent-header")).map((element, id) => ({
|
||||
page: "Guide_to_chemistry",
|
||||
name: element
|
||||
.querySelector("th .reagent-header")
|
||||
.textContent.trim()
|
||||
.replace(/\n.+$/gm, "")
|
||||
.replace("▮", ""),
|
||||
element,
|
||||
alignment: "center",
|
||||
|
|
|
@ -41,6 +41,7 @@ export function processFood(root: HTMLElement): void {
|
|||
];
|
||||
baseFoodTables.forEach(({ selector, title, process }) => {
|
||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||
if (!table) return;
|
||||
const foods = parseTable(table).map((row) => {
|
||||
const foodBlock = document.createElement("td");
|
||||
foodBlock.innerHTML = `<div class="food-block">
|
||||
|
@ -108,6 +109,7 @@ export function processFood(root: HTMLElement): void {
|
|||
];
|
||||
foodRecipesTables.forEach((selector) => {
|
||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||
if (!table) return;
|
||||
const recipes = parseTable(table).map((row) => {
|
||||
const foodBlock = document.createElement("td");
|
||||
foodBlock.innerHTML = `
|
||||
|
|
|
@ -2,7 +2,7 @@ import { registerSearchEntries } from "../search";
|
|||
|
||||
export function genericScript(root: HTMLElement, docname: string): void {
|
||||
const el = Array.from(
|
||||
root.querySelectorAll<HTMLElement>("div.mw-headline-cont[id][data-name]")
|
||||
root.querySelectorAll<HTMLElement>(".mw-headline-cont[id][data-name]")
|
||||
);
|
||||
|
||||
// Init fuzzy search with headlines
|
||||
|
|
|
@ -75,7 +75,10 @@ export function processGlobal(root: HTMLElement, docname: string): void {
|
|||
if (toc) {
|
||||
const tocHeader = toc.querySelector("h2");
|
||||
toc.parentNode.insertBefore(tocHeader, toc);
|
||||
toc.removeChild(toc.querySelector("#toctitle"));
|
||||
const tocTitle = toc.querySelector("#toctitle")
|
||||
if (tocTitle != null) {
|
||||
toc.removeChild(tocTitle);
|
||||
}
|
||||
}
|
||||
|
||||
// Group headers and content so stickies don't overlap
|
||||
|
@ -99,10 +102,13 @@ export function processGlobal(root: HTMLElement, docname: string): void {
|
|||
const container = findParent(span, (el) =>
|
||||
el.classList.contains("mw-headline-cont")
|
||||
);
|
||||
if (container) {
|
||||
if (container && container.querySelectorAll<HTMLElement>(".mw-headline").length === 1) {
|
||||
container.id = span.id;
|
||||
span.id += "-span";
|
||||
container.dataset.name = span.textContent;
|
||||
} else {
|
||||
span.dataset.name = span.textContent;
|
||||
span.classList.add("mw-headline-cont");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue