-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.js
44 lines (35 loc) · 1.21 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { createElement, hydrate, Component } from "preact";
import htm from "htm"; const html = htm.bind(createElement);
import { PictureGallery, getInitialPageTitle } from "./components/picture-gallery.js";
import { Catcher } from "./components/catcher.js";
import { getAlbumByURL } from "./data/album-by-url.js";
import { getConfigData } from "./data/config.js";
function getPageURL() {
return window.location.href;
}
async function start() {
const album = await getAlbumByURL({ url: getPageURL(), fetch });
const config = await getConfigData({ fetch });
console.log({album});
hydrate(
html`
<${Catcher} originalBodyInnerHTML="${document.body.innerHTML}">
<${PictureGallery}
getPageURL="${getPageURL}"
pictures="${album.pictures}"
story="${album.story}"
album="${album}"
config="${config}"
/>
</${Catcher}>
`,
document.body
);
// document.title = getInitialPageTitle({ getPageURL, album, pictures: album.pictures });
}
// https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", start);
} else {
start();
}