@rr0/cms 0.3.66 → 0.3.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,6 +14,15 @@ export declare class DataContentVisitor implements ContentVisitor {
|
|
|
14
14
|
visit(context: HtmlRR0Context): Promise<void>;
|
|
15
15
|
protected process(context: HtmlRR0Context, data: RR0Data): Promise<void>;
|
|
16
16
|
protected processEvent(context: HtmlRR0Context, event: RR0Event, data: RR0Data): Promise<void>;
|
|
17
|
+
/** Where the UFO@home player that replays a case's sightings is served from. */
|
|
18
|
+
static readonly SIGHTING_PLAYER_SCRIPT = "https://ufoathome.org/lib/rr0-sighting.mjs";
|
|
19
|
+
/**
|
|
20
|
+
* A sighting event of a case points at a witness's recording (its `url`, a UFO@home
|
|
21
|
+
* `sighting.json`): the page shows them in the UFO@home player, reading the case.json itself so
|
|
22
|
+
* that every sighting of the case is offered, not only this one. Inserted at the end of the page's
|
|
23
|
+
* contents, once, and only if the page does not already embed a player where its author put one.
|
|
24
|
+
*/
|
|
25
|
+
protected processSighting(context: HtmlRR0Context, data: RR0Data): void;
|
|
17
26
|
protected timeParagraph(context: HtmlRR0Context, event: RR0Event): {
|
|
18
27
|
eventP: HTMLParagraphElement;
|
|
19
28
|
timeEl: HTMLElement;
|
|
@@ -46,12 +46,38 @@ export class DataContentVisitor {
|
|
|
46
46
|
case "death":
|
|
47
47
|
await this.processDeath(context, event, data);
|
|
48
48
|
break;
|
|
49
|
+
case "sighting":
|
|
50
|
+
this.processSighting(context, data);
|
|
51
|
+
break;
|
|
49
52
|
default:
|
|
50
53
|
const { eventP, timeEl } = this.timeParagraph(context, event);
|
|
51
54
|
await this.eventRenderer.render(context, event, eventP);
|
|
52
55
|
context.file.document.append(eventP);
|
|
53
56
|
}
|
|
54
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* A sighting event of a case points at a witness's recording (its `url`, a UFO@home
|
|
60
|
+
* `sighting.json`): the page shows them in the UFO@home player, reading the case.json itself so
|
|
61
|
+
* that every sighting of the case is offered, not only this one. Inserted at the end of the page's
|
|
62
|
+
* contents, once, and only if the page does not already embed a player where its author put one.
|
|
63
|
+
*/
|
|
64
|
+
processSighting(context, data) {
|
|
65
|
+
const doc = context.file.document;
|
|
66
|
+
if (data.type !== "case" || doc.querySelector("rr0-sighting")) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const parentEl = doc.querySelector(".contents") || doc.body;
|
|
70
|
+
if (!parentEl) {
|
|
71
|
+
context.warn("no .contents to insert the sighting player in", context.file.name);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const scriptEl = doc.createElement("script");
|
|
75
|
+
scriptEl.type = "module";
|
|
76
|
+
scriptEl.src = DataContentVisitor.SIGHTING_PLAYER_SCRIPT;
|
|
77
|
+
const playerEl = doc.createElement("rr0-sighting");
|
|
78
|
+
playerEl.setAttribute("src", "case.json");
|
|
79
|
+
parentEl.append(scriptEl, playerEl);
|
|
80
|
+
}
|
|
55
81
|
timeParagraph(context, event) {
|
|
56
82
|
const container = context.file.document.createElement("p");
|
|
57
83
|
const eventContext = context.clone();
|
|
@@ -155,3 +181,5 @@ export class DataContentVisitor {
|
|
|
155
181
|
}
|
|
156
182
|
}
|
|
157
183
|
}
|
|
184
|
+
/** Where the UFO@home player that replays a case's sightings is served from. */
|
|
185
|
+
DataContentVisitor.SIGHTING_PLAYER_SCRIPT = "https://ufoathome.org/lib/rr0-sighting.mjs";
|
|
@@ -8,6 +8,9 @@ class TestDataContentVisitor extends DataContentVisitor {
|
|
|
8
8
|
renderImage(context, event) {
|
|
9
9
|
return this.processImage(context, event);
|
|
10
10
|
}
|
|
11
|
+
renderEvent(context, event, data) {
|
|
12
|
+
return this.processEvent(context, event, data);
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
15
|
describe("DataContentVisitor", () => {
|
|
13
16
|
const portraitEvent = {
|
|
@@ -31,4 +34,27 @@ describe("DataContentVisitor", () => {
|
|
|
31
34
|
await visitor.renderImage(context, portraitEvent);
|
|
32
35
|
expect(context.file.document.querySelectorAll(".contents img[src=\"portrait.jpg\"]").length).toBe(1);
|
|
33
36
|
});
|
|
37
|
+
const sightingEvent = { type: "event", eventType: "sighting", url: "sighting.json" };
|
|
38
|
+
const aCase = { type: "case", events: [sightingEvent] };
|
|
39
|
+
test("inserts the UFO@home player on the case, for a case with a sighting and no player", async () => {
|
|
40
|
+
const context = cmsTestUtil.newHtmlContext("people/v/VertongenJeanLuc/index.html", "<div class=\"contents\"><p>Le dossier</p></div>");
|
|
41
|
+
const visitor = new TestDataContentVisitor();
|
|
42
|
+
await visitor.renderEvent(context, sightingEvent, aCase);
|
|
43
|
+
await visitor.renderEvent(context, sightingEvent, aCase);
|
|
44
|
+
const players = context.file.document.querySelectorAll(".contents > rr0-sighting");
|
|
45
|
+
expect(players.length).toBe(1);
|
|
46
|
+
expect(players[0].getAttribute("src")).toBe("case.json");
|
|
47
|
+
const script = context.file.document.querySelector(".contents > script");
|
|
48
|
+
expect(script === null || script === void 0 ? void 0 : script.getAttribute("src")).toBe(DataContentVisitor.SIGHTING_PLAYER_SCRIPT);
|
|
49
|
+
expect(script === null || script === void 0 ? void 0 : script.getAttribute("type")).toBe("module");
|
|
50
|
+
// Nothing else: no dated paragraph per sighting, which a sighting without a time used to fail the build on.
|
|
51
|
+
expect(context.file.document.querySelectorAll(".contents > p").length).toBe(1);
|
|
52
|
+
});
|
|
53
|
+
test("leaves a player the page's author placed alone", async () => {
|
|
54
|
+
const context = cmsTestUtil.newHtmlContext("people/v/VertongenJeanLuc/index.html", "<div class=\"contents\"><p>Le dossier</p><rr0-sighting src=\"case.json\" show-witness-map></rr0-sighting></div>");
|
|
55
|
+
const visitor = new TestDataContentVisitor();
|
|
56
|
+
await visitor.renderEvent(context, sightingEvent, aCase);
|
|
57
|
+
expect(context.file.document.querySelectorAll("rr0-sighting").length).toBe(1);
|
|
58
|
+
expect(context.file.document.querySelectorAll("script").length).toBe(0);
|
|
59
|
+
});
|
|
34
60
|
});
|
package/package.json
CHANGED