diff --git a/src/components.js b/src/components.js
index 32eb8f0..c8937a1 100644
--- a/src/components.js
+++ b/src/components.js
@@ -1,3 +1,10 @@
+/* Flag that we're being loaded */
+if (window.distillLoaded) {
+ throw new Error('Distill Template is getting loaded more than once, aborting!');
+} else {
+ window.distillLoaded = true;
+}
+
/* Static styles and other modules */
import { makeStyleTag } from './styles/styles';
makeStyleTag(document);
@@ -20,8 +27,7 @@ import { References } from './components/d-references';
import { TOC } from './components/d-toc';
import { Figure } from './components/d-figure';
import { Interstitial } from './components/d-interstitial';
-
-import { Slider } from './ui/d-slider';
+import { Slider } from './ui/d-slider';
const components = [
Abstract, Appendix, Article, Bibliography, Byline, Cite, CitationList, Code,
diff --git a/src/components/d-article.js b/src/components/d-article.js
index 5085868..d228079 100644
--- a/src/components/d-article.js
+++ b/src/components/d-article.js
@@ -14,9 +14,6 @@ export class Article extends HTMLElement {
for (const mutation of mutations) {
for (const addedNode of mutation.addedNodes) {
switch (addedNode.nodeName) {
- // case 'HR':
- // console.warn('Use of
tags in distill articles is discouraged as they interfere with layout! To separate sections, please just use h2 or h3 tags.');
- // break;
case '#text': { // usually text nodes are only linebreaks.
const text = addedNode.nodeValue;
if (!isOnlyWhitespace.test(text)) {
diff --git a/src/components/d-bibliography.js b/src/components/d-bibliography.js
index 6b6135e..f88bbad 100644
--- a/src/components/d-bibliography.js
+++ b/src/components/d-bibliography.js
@@ -1,9 +1,16 @@
import { parseBibtex } from '../helpers/bibtex';
export function parseBibliography(element) {
- if (element.firstElementChild && element.firstElementChild.tagName === 'SCRIPT') {
- const bibtex = element.firstElementChild.textContent;
- return parseBibtex(bibtex);
+ const scriptTag = element.firstElementChild;
+ if (scriptTag && scriptTag.tagName === 'SCRIPT') {
+ if (scriptTag.type == 'text/bibtex') {
+ const bibtex = element.firstElementChild.textContent;
+ return parseBibtex(bibtex);
+ } else if (scriptTag.type == 'text/json') {
+ return new Map(JSON.parse(scriptTag.textContent));
+ } else {
+ console.warn('Unsupported bibliography script tag type: ' + scriptTag.type);
+ }
}
}
diff --git a/src/components/d-figure.js b/src/components/d-figure.js
index 2df9302..a3e1c47 100644
--- a/src/components/d-figure.js
+++ b/src/components/d-figure.js
@@ -166,7 +166,6 @@ if (typeof window !== 'undefined') {
clearTimeout(timeout);
timeout = setTimeout(() => {
Figure.isScrolling = false;
- console.log('Stopped Scrolling')
Figure.runReadyQueue();
}, 500);
};
diff --git a/src/distill-components/distill-appendix.js b/src/distill-components/distill-appendix.js
index 6770b0e..924dedc 100644
--- a/src/distill-components/distill-appendix.js
+++ b/src/distill-components/distill-appendix.js
@@ -30,21 +30,34 @@ const styles = `
`;
export function appendixTemplate(frontMatter) {
- return `
- ${styles}
+ let html = styles;
- Updates and Corrections
- View all changes to this article since it was first published. If you see mistakes or want to suggest changes, please create an issue on GitHub.
+ if (typeof frontMatter.githubUrl !== 'undefined') {
+ html += `
+ Updates and Corrections
+ View all changes to this article since it was first published. If you see mistakes or want to suggest changes, please create an issue on GitHub.
+ `;
+ }
- Reuse
- Diagrams and text are licensed under Creative Commons Attribution CC-BY 4.0 with the source available on GitHub, unless noted otherwise. The figures that have been reused from other sources don’t fall under this license and can be recognized by a note in their caption: “Figure from …”.
+ const journal = frontMatter.journal;
+ if (typeof journal !== 'undefined' && journal.title === 'Distill') {
+ html += `
+ Reuse
+ Diagrams and text are licensed under Creative Commons Attribution CC-BY 4.0 with the source available on GitHub, unless noted otherwise. The figures that have been reused from other sources don’t fall under this license and can be recognized by a note in their caption: “Figure from …”.
+ `;
+ }
- Citation
- For attribution in academic contexts, please cite this work as
- ${frontMatter.concatenatedAuthors}, "${frontMatter.title}", Distill, ${frontMatter.publishedYear}.
- BibTeX citation
- ${serializeFrontmatterToBibtex(frontMatter)}
- `;
+ if (typeof frontMatter.publishedDate !== 'undefined') {
+ html += `
+ Citation
+ For attribution in academic contexts, please cite this work as
+ ${frontMatter.concatenatedAuthors}, "${frontMatter.title}", Distill, ${frontMatter.publishedYear}.
+ BibTeX citation
+ ${serializeFrontmatterToBibtex(frontMatter)}
+ `;
+ }
+
+ return html;
}
export class DistillAppendix extends HTMLElement {
diff --git a/src/distill-components/distill-header.js b/src/distill-components/distill-header.js
index e312543..8e4cb2a 100644
--- a/src/distill-components/distill-header.js
+++ b/src/distill-components/distill-header.js
@@ -4,80 +4,81 @@ import logo from '../assets/distill-logo.svg';
const T = Template('distill-header', `
-
-
+
${logo}
-
-
-`);
+`, false);
//
//
GitHub
diff --git a/src/front-matter.js b/src/front-matter.js
index a450b04..f247974 100644
--- a/src/front-matter.js
+++ b/src/front-matter.js
@@ -143,7 +143,7 @@ export class FrontMatter {
// githubCompareUpdatesUrl: 'https://github.com/distillpub/post--augmented-rnns/compare/1596e094d8943d2dc0ea445d92071129c6419c59...3bd9209e0c24d020f87cf6152dcecc6017cbc193',
// updatedDate: 2017-03-21T07:13:16.000Z,
// doi: '10.23915/distill.00001',
-
+ this.publishedDate = undefined;
}
// Example:
@@ -176,7 +176,11 @@ export class FrontMatter {
// 'https://github.com/distillpub/post--augmented-rnns',
get githubUrl() {
- return 'https://github.com/' + this.githubPath;
+ if (this.githubPath) {
+ return 'https://github.com/' + this.githubPath;
+ } else {
+ return undefined;
+ }
}
// TODO resolve differences in naming of URL/Url/url.
diff --git a/src/styles/styles-base.css b/src/styles/styles-base.css
index baa87ba..09ed608 100644
--- a/src/styles/styles-base.css
+++ b/src/styles/styles-base.css
@@ -52,6 +52,17 @@ p {
margin-bottom: 1em;
}
+sup, sub {
+ vertical-align: baseline;
+ position: relative;
+ top: -0.4em;
+ line-height: 1em;
+}
+
+sub {
+ top: 0.4em;
+}
+
.kicker,
.marker {
font-size: 15px;
diff --git a/src/transforms.js b/src/transforms.js
index dcc5125..72379cf 100644
--- a/src/transforms.js
+++ b/src/transforms.js
@@ -52,7 +52,12 @@ const distillTransforms = new Map([
/* Exported functions */
export function render(dom, data, verbose=true) {
- const frontMatter = FrontMatter.fromObject(data);
+ let frontMatter;
+ if (data instanceof FrontMatter) {
+ frontMatter = data;
+ } else {
+ frontMatter = FrontMatter.fromObject(data);
+ }
// first, we collect static data from the dom
for (const [name, extract] of extractors.entries()) {
if (verbose) console.warn('Running extractor: ' + name);
@@ -66,7 +71,11 @@ export function render(dom, data, verbose=true) {
}
dom.body.setAttribute('distill-prerendered', '');
// the function calling us can now use the transformed dom and filled data object
- frontMatter.assignToObject(data);
+ if (data instanceof FrontMatter) {
+ // frontMatter will already have needed properties
+ } else {
+ frontMatter.assignToObject(data);
+ }
}
export function distillify(dom, data, verbose=true) {
diff --git a/src/transforms/optional-components.js b/src/transforms/optional-components.js
index 410dfbc..9409c67 100644
--- a/src/transforms/optional-components.js
+++ b/src/transforms/optional-components.js
@@ -9,17 +9,21 @@
export default function(dom, data) {
const article = dom.querySelector('d-article');
-
if (!article) {
- console.warn('No d-article tag found!');
+ console.warn('No d-article tag found; skipping adding optional components!');
return;
}
+ const hasPassword = typeof data.password !== 'undefined';
let interstitial = dom.querySelector('d-interstitial');
- if (!interstitial && data.password) {
- interstitial = dom.createElement('d-interstitial');
- interstitial.password = data.password;
- dom.body.insertBefore(interstitial, dom.body.firstChild);
+ if (hasPassword && !interstitial) {
+ const inBrowser = typeof window !== 'undefined';
+ const onLocalhost = inBrowser && window.location.hostname.includes('localhost');
+ if (!inBrowser || !onLocalhost) {
+ interstitial = dom.createElement('d-interstitial');
+ interstitial.password = data.password;
+ dom.body.insertBefore(interstitial, dom.body.firstChild);
+ }
}
// let h1 = dom.querySelector('h1');