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,8 +18,13 @@ export const PAGE_VERSIONS = {
|
||||||
const MAX_WIDTH = 440;
|
const MAX_WIDTH = 440;
|
||||||
|
|
||||||
export function processHTML(root: HTMLElement, docname: string): void {
|
export function processHTML(root: HTMLElement, docname: string): void {
|
||||||
|
try {
|
||||||
processGlobal(root, docname);
|
processGlobal(root, docname);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Error processing page: ${docname}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
switch (docname) {
|
switch (docname) {
|
||||||
case "Guide_to_chemistry":
|
case "Guide_to_chemistry":
|
||||||
processChemistry(root);
|
processChemistry(root);
|
||||||
|
@ -35,6 +40,9 @@ export function processHTML(root: HTMLElement, docname: string): void {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Error processing page: ${docname} (specific enhancements)`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
|
|
@ -204,11 +204,11 @@ export function chemistryScript(root: HTMLElement): void {
|
||||||
);
|
);
|
||||||
|
|
||||||
registerSearchEntries(
|
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",
|
page: "Guide_to_chemistry",
|
||||||
name: element
|
name: element
|
||||||
.querySelector("th .reagent-header")
|
|
||||||
.textContent.trim()
|
.textContent.trim()
|
||||||
|
.replace(/\n.+$/gm, "")
|
||||||
.replace("▮", ""),
|
.replace("▮", ""),
|
||||||
element,
|
element,
|
||||||
alignment: "center",
|
alignment: "center",
|
||||||
|
|
|
@ -41,6 +41,7 @@ export function processFood(root: HTMLElement): void {
|
||||||
];
|
];
|
||||||
baseFoodTables.forEach(({ selector, title, process }) => {
|
baseFoodTables.forEach(({ selector, title, process }) => {
|
||||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||||
|
if (!table) return;
|
||||||
const foods = parseTable(table).map((row) => {
|
const foods = parseTable(table).map((row) => {
|
||||||
const foodBlock = document.createElement("td");
|
const foodBlock = document.createElement("td");
|
||||||
foodBlock.innerHTML = `<div class="food-block">
|
foodBlock.innerHTML = `<div class="food-block">
|
||||||
|
@ -108,6 +109,7 @@ export function processFood(root: HTMLElement): void {
|
||||||
];
|
];
|
||||||
foodRecipesTables.forEach((selector) => {
|
foodRecipesTables.forEach((selector) => {
|
||||||
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
const table = root.querySelector<HTMLElement>(`${selector} .wikitable`);
|
||||||
|
if (!table) return;
|
||||||
const recipes = parseTable(table).map((row) => {
|
const recipes = parseTable(table).map((row) => {
|
||||||
const foodBlock = document.createElement("td");
|
const foodBlock = document.createElement("td");
|
||||||
foodBlock.innerHTML = `
|
foodBlock.innerHTML = `
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { registerSearchEntries } from "../search";
|
||||||
|
|
||||||
export function genericScript(root: HTMLElement, docname: string): void {
|
export function genericScript(root: HTMLElement, docname: string): void {
|
||||||
const el = Array.from(
|
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
|
// Init fuzzy search with headlines
|
||||||
|
|
|
@ -75,7 +75,10 @@ export function processGlobal(root: HTMLElement, docname: string): void {
|
||||||
if (toc) {
|
if (toc) {
|
||||||
const tocHeader = toc.querySelector("h2");
|
const tocHeader = toc.querySelector("h2");
|
||||||
toc.parentNode.insertBefore(tocHeader, toc);
|
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
|
// 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) =>
|
const container = findParent(span, (el) =>
|
||||||
el.classList.contains("mw-headline-cont")
|
el.classList.contains("mw-headline-cont")
|
||||||
);
|
);
|
||||||
if (container) {
|
if (container && container.querySelectorAll<HTMLElement>(".mw-headline").length === 1) {
|
||||||
container.id = span.id;
|
container.id = span.id;
|
||||||
span.id += "-span";
|
span.id += "-span";
|
||||||
container.dataset.name = span.textContent;
|
container.dataset.name = span.textContent;
|
||||||
|
} else {
|
||||||
|
span.dataset.name = span.textContent;
|
||||||
|
span.classList.add("mw-headline-cont");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue