Skip to content

Commit

Permalink
Handle notice articles
Browse files Browse the repository at this point in the history
  • Loading branch information
Nufflee committed Dec 30, 2023
1 parent 2407f29 commit e4fc1b1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NodeType, parse } from "node-html-parser";

const colors = {
Report: "#89a0fa",
Incident: "#feff45",
Accident: "#e58326",
Crash: "#e52f18",
const COLORS = {
Notice: "#00FF00",
Report: "#89A0FA",
Incident: "#FEFF45",
Accident: "#E58326",
Crash: "#E52F18",
};

export async function generateHTML(articleId: string) {
Expand Down Expand Up @@ -33,10 +34,17 @@ export async function generateHTML(articleId: string) {
const content = parsed.querySelector("td > div > .sitetext");
const images = content!.querySelectorAll("img");

const color = colors[title.split(":")[0]];
let color: string;

// Strip incident type out of the title, it's already indicated by the color
title = title.split(":")[1].trim();
if (title.includes(":")) {
color = COLORS[title.split(":")[0]];

// Strip incident type out of the title as it's already indicated by the color
title = title.split(":")[1].trim();
} else {
// If there's no accident type in the title, assume it's a notice
color = COLORS["Notice"];
}

let contentText = content!.childNodes
.map((node, i) => {
Expand Down

0 comments on commit e4fc1b1

Please sign in to comment.