-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconstructPage.js
60 lines (53 loc) · 1.54 KB
/
constructPage.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import buildPage from "./buildPage";
import buildProgressBar from "./progressBar";
export default function (
analytics,
cache,
containerSelector,
defaultAnimation,
localLinkDetector,
progressBar,
progressBarOptions,
scanOnMount,
scrollIntoView,
scrollIntoViewOptions
) {
const builtPage = buildPage(
containerSelector,
scrollIntoView,
scrollIntoViewOptions,
localLinkDetector,
scanOnMount,
analytics,
defaultAnimation
);
return `const constructPage = async () => {
window.dispatchEvent(new Event("navigate"));
window.onNavigate && window.onNavigate();
${buildProgressBar(progressBar, progressBarOptions)}
const cachedPage = ${
cache
? `(await cache.match(location.href)) ||
(await (cachePage(location.href))) ||
(await cache.match(location.href));`
: "(await fetch(location.href));"
}
const html = await cachedPage.text();
const doc = new DOMParser().parseFromString(html, "text/html");
${
progressBar
? progressBarOptions?.secondary
? `clearInterval(intervalID);
${containerSelector ? "progressBar.remove();bgProgressBar.remove();" : ""}
${builtPage}`
: `clearInterval(intervalID);
progressBar.animate({ width: [pbw + "vw", "100vw"] }, 100).onfinish =
() => {
${containerSelector ? "progressBar.remove();" : ""}
${builtPage}
};`
: builtPage
}
document.getElementById("astro-spa-live-region").textContent = document.title;
};`;
}