-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.hbs
91 lines (82 loc) · 3.42 KB
/
default.hbs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<html lang="{{@site.locale}}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preload" href="{{asset "built/screen.css"}}" as="style">
<link rel="stylesheet" href="{{asset "built/index.css"}}">
<link rel="preconnect" href="https://use.typekit.net" crossorigin>
<link rel="preconnect" href="https://p.typekit.net" crossorigin>
<link rel="preload" as="style" href="https://use.typekit.net/unt3hxg.css">
<link rel="stylesheet" href="https://use.typekit.net/unt3hxg.css">
<script src="https://kit.fontawesome.com/6c2d249101.js" crossorigin="anonymous"></script>
<title>{{meta_title}}</title>
{{ghost_head}}
</head>
<body class="{{body_class}}{{#is "notes,quotes"}}notes{{/is}}{{#is "jeeps"}}jeeps{{/is}}{{#is "articles"}}articles{{/is}}">
<div class="px-8">
{{{body}}}
{{> "footer"}}
</div>
<script src="{{asset "built/index.js"}}" defer></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@justinribeiro/lite-youtube@1.5.0/lite-youtube.js"></script>
{{#is 'post'}}
<script>document.getElementById("showCommentsBtn").onclick=function(){var e=document.getElementById("commentBlock");"none"===e.style.display?e.style.display="block":e.style.display="none"};</script>
{{/is}}
<script>
// @ts-check
/* global maxPages */
class InfiniteLoader {
static NOT_A_DOM = Symbol('not a dom');
constructor() {
/** @type {DocumentFragment} */
this._nextDom = document;
this._loader = document.getElementById('read-more-trigger');
this._postList = document.querySelector('.gh-postfeed');
this._subscribeToLoadMore();
this.loadNextPage();
}
_subscribeToLoadMore() {
this._loader?.addEventListener('click', () => {
this.loadNextPage();
for (const post of this._nextDom.querySelectorAll('.post')) {
this._postList.appendChild(post);
}
});
}
loadNextPage() {
return this._loadNextPage().catch(() => {
this._loader.style.display = 'none';
if (!this._nextDom[InfiniteLoader.NOT_A_DOM]) {
this._nextDom = document.createRange().createContextualFragment('');
this._nextDom[InfiniteLoader.NOT_A_DOM] = true;
}
});
}
async _loadNextPage() {
const activeDom = this._nextDom;
/** @type {HTMLLinkElement} */
const next = activeDom.querySelector('link[rel="next"]');
if (!next?.href) {
throw new Error('does not contain link[rel="next"]');
}
const response = await fetch(next.href);
if (response.status === 404) {
throw new Error('got 404');
}
this._nextDom = document.createRange().createContextualFragment(await response.text());
debugger;
if (!this._nextDom.querySelector('.post')) {
throw new Error('got page but it has no posts');
}
}
}
// @ts-expect-error
window.__components = {
infiniteLoader: new InfiniteLoader()
};
</script>
{{ghost_foot}}
</body>
</html>