-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
47 lines (45 loc) · 1.39 KB
/
index.html
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
<!DOCTYPE html>
<body>
<div class="wrapper">
<div id="title"></div>
<div id="description"></div>
<div id="hientrang"></div>
<div id="style"></div>
</div>
</div>
<script type="module">
import {Runtime} from "https://unpkg.com/@observablehq/runtime@4/dist/runtime.js";
import notebook from "https://api.observablehq.com/@kuquanghuylcb/nghien-cuu-gia-sach.js?v=3";
const renders = {
"title":"#title",
"description":"#description",
"html_hientrang":"#hientrang",
"style":"#style",
};
function render(_node, value) {
if (!(value instanceof Element)) {
const el = document.createElement("span");
el.innerHTML = value;
value = el;
}
if (_node.firstChild !== value) {
if (_node.firstChild) {
while (_node.lastChild !== _node.firstChild) _node.removeChild(_node.lastChild);
_node.replaceChild(value, _node.firstChild);
} else {
_node.appendChild(value);
}
}
}
const runtime = new Runtime();
const main = runtime.module(notebook, name => {
const selector = renders[name];
if (selector) {
return {fulfilled: (value) => render(document.querySelector(selector), value)}
} else {
return true;
}
});
</script>
</body>
</html>