mirror of
https://github.com/wassname/template.git
synced 2026-06-27 20:07:28 +08:00
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
// Copyright 2018 The Distill Template Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
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 DTMath from "./components/dt-math";
|
|
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);
|
|
DTMath(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);
|
|
}
|
|
|
|
export {render as render};
|
|
export {distillify as distillify};
|
|
export {generateCrossref as generateCrossref};
|