@rr0/cms
Version:
RR0 Content Management System (CMS)
64 lines (63 loc) • 3.13 kB
JavaScript
import path from "path";
import { TimeContext } from "../time/TimeContext.mjs";
export class CaseAnchorHandler {
constructor(caseService, timeTextBuilder) {
this.caseService = caseService;
this.timeTextBuilder = timeTextBuilder;
}
async handle(context, link, pathToSearch) {
var _a, _b, _c, _d, _e, _f;
if (!link.title) {
const foundCases = await this.caseService.getFromDir(pathToSearch);
const aCase = foundCases[0];
if (aCase) {
const caseContext = context.clone();
caseContext.time.reset();
const titles = [];
const caseTitle = aCase.title;
if (caseTitle && !titles.includes(caseTitle)) {
titles.push(caseTitle);
}
const classification = aCase.classification;
const hynek = classification === null || classification === void 0 ? void 0 : classification.hynek;
if (hynek) {
const classificationLabels = context.messages.case.classification.hynek[hynek];
titles.push(classificationLabels.long);
}
const caseTime = aCase.time;
if (caseTime) {
if (typeof caseTime === "string") {
if (!titles.includes(caseTime)) {
caseContext.time.updateFromStr(caseTime);
}
}
else {
caseContext.time = new TimeContext((_a = caseTime.year) === null || _a === void 0 ? void 0 : _a.value, (_b = caseTime.month) === null || _b === void 0 ? void 0 : _b.value, (_c = caseTime.day) === null || _c === void 0 ? void 0 : _c.value, (_d = caseTime.hour) === null || _d === void 0 ? void 0 : _d.value, (_e = caseTime.minute) === null || _e === void 0 ? void 0 : _e.value, (_f = caseTime.timeshift) === null || _f === void 0 ? void 0 : _f.toString());
}
titles.push(this.timeTextBuilder.build(caseContext));
}
const place = aCase.place;
if (typeof place === "string" && !titles.includes(place)) {
titles.push(place);
}
const conclusion = aCase.conclusion;
if (conclusion && !titles.includes(conclusion)) {
link.classList.add(conclusion);
titles.push(context.messages.case.conclusion[conclusion]);
}
const image = aCase.image;
if (image) {
const doc = context.file.document;
const imgEl = doc.createElement("img");
imgEl.src = path.join("/", image);
imgEl.alt = aCase.title;
imgEl.className = "portrait";
imgEl.loading = "lazy";
imgEl.width = 75;
link.append(imgEl);
}
link.title = titles.join(", ");
}
}
}
}