forked from raminmh/template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
102 lines (95 loc) · 2.87 KB
/
index.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
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
92
93
94
95
96
97
98
99
100
101
102
import html from "./components/html";
import styles from "./components/styles";
import frontMatter from "./components/front-matter";
import bibliography from "./components/bibliography";
import expandData from "./components/data";
import meta from "./components/meta";
import banner from "./components/banner";
import byline from "./components/byline";
import appendix from "./components/appendix";
import appendixDistill from "./components/appendix-distill";
import citation from "./components/citation";
import footnote from "./components/footnote";
import markdown from "./components/markdown";
import code from "./components/code";
import typeset from "./components/typeset";
import hoverBox from "./components/hover-box-include";
import generateCrossref from "./components/generate-crossref";
import header from "./components/header";
import footer from "./components/footer";
function renderImmediately(dom) {
html(dom);
styles(dom);
}
function renderOnLoad(dom, data) {
frontMatter(dom, data);
bibliography(dom, data);
expandData(dom, data);
meta(dom, data);
byline(dom, data);
appendix(dom, data);
markdown(dom, data);
code(dom, data);
citation(dom, data);
footnote(dom, data);
typeset(dom, data);
hoverBox(dom, data);
}
// If we are in a browser, render automatically...
var browser = new Function("try { return this === window; }catch(e){ return false; }");
if (browser()) {
try {
var data = {};
renderImmediately(window.document);
window.document.addEventListener("DOMContentLoaded", function (event) {
renderOnLoad(window.document, data);
// Add a banner if we're not on localhost.
if (window.location.hostname !== "localhost" && window.location.origin !== "file://") {
banner(window.document, data);
}
generateCrossref(data);
// console.log(data);
});
} catch (error) {
console.error("Window not defined");
}
}
// If we are in node...
function render(dom, data) {
renderImmediately(dom);
renderOnLoad(dom, data);
// Remove script tag so it doesn't run again in the client
let s = dom.querySelector('script[src*="distill.pub/template"]');
if (s) { s.parentElement.removeChild(s); };
}
// Distill specific rendering
function distillify(dom, data) {
header(dom, data);
appendixDistill(dom, data);
footer(dom, data);
}
let components = {
html: html,
styles: styles,
frontMatter: frontMatter,
bibliography: bibliography,
expandData: expandData,
meta: meta,
banner: banner,
byline: byline,
appendix: appendix,
appendixDistill: appendixDistill,
citation: citation,
footnote: footnote,
markdown: markdown,
code: code,
typeset: typeset,
hoverBox: hoverBox,
generateCrossref: generateCrossref,
header: header,
footer: footer,
};
export {render as render};
export {distillify as distillify};
export {generateCrossref as generateCrossref};
export {components as components};