Fix linter warnings except for /transforms

This commit is contained in:
Ludwig Schubert
2017-08-09 16:47:35 -07:00
parent 11eda0fc49
commit 27fbe9a932
42 changed files with 460 additions and 478 deletions
+1
View File
@@ -11,6 +11,7 @@
"rules": {
"no-unused-vars": ["warn", { "vars": "all", "args": "after-used" }],
"no-console": ["off", { "allow": ["warn", "error"] } ],
"no-empty": ["error", { "allowEmptyCatch": true }],
"indent": [ "warn", 2 ],
"linebreak-style": [ "error", "unix" ],
"quotes": [ "warn", "single" ],
+4 -4
View File
@@ -1,7 +1,7 @@
import { Template } from "../mixins/template";
import { body } from "../helpers/layout";
import { Template } from '../mixins/template';
import { body } from '../helpers/layout';
const T = Template("d-abstract", `
const T = Template('d-abstract', `
<style>
d-abstract {
display: block;
@@ -9,7 +9,7 @@ const T = Template("d-abstract", `
line-height: 1.7em;
margin-bottom: 140px;
}
${body("d-abstract")}
${body('d-abstract')}
</style>
`, false);
+1 -1
View File
@@ -1,4 +1,4 @@
import { Template } from "../mixins/template";
import { Template } from '../mixins/template';
const T = Template('d-acknowledgements', `
<style>
+4 -4
View File
@@ -1,7 +1,7 @@
import { Template } from "../mixins/template";
import { page } from "../helpers/layout";
import { Template } from '../mixins/template';
import { page } from '../helpers/layout';
const T = Template("d-appendix", `
const T = Template('d-appendix', `
<style>
:host {
@@ -16,7 +16,7 @@ const T = Template("d-appendix", `
padding-bottom: 48px;
}
${page(".l-body")}
${page('.l-body')}
</style>
+1 -1
View File
@@ -18,7 +18,7 @@ export class Article extends T(HTMLElement) {
if (typeof callback === 'function') {
document.addEventListener(functionName, callback);
} else {
console.error('Controller listeners need to be functions!')
console.error('Controller listeners need to be functions!');
}
}
}
+23 -37
View File
@@ -1,8 +1,6 @@
import { Template } from "../mixins/template";
import { Mutating } from "../mixins/mutating";
import { collectCitations } from './d-cite'
import bibtexParse from "bibtex-parse-js";
import { bibliography_cite } from "../helpers/citation";
import { Template } from '../mixins/template';
import bibtexParse from 'bibtex-parse-js';
import { bibliography_cite } from '../helpers/citation';
const T = Template('d-bibliography', `
<style>
@@ -43,11 +41,11 @@ export function parseBibtex(bibtex) {
// normalize tags; note entryTags is an object, not Map
for (const tag in entry.entryTags) {
let value = entry.entryTags[tag];
value = value.replace(/[\t\n ]+/g, " ");
value = value.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g,
(full, x, char) => char);
value = value.replace(/[\t\n ]+/g, ' ');
value = value.replace(/{\\["^`.'acu~Hvs]( )?([a-zA-Z])}/g,
(full, x, char) => char);
value = value.replace(/{\\([a-zA-Z])}/g,
(full, char) => char);
(full, char) => char);
entry.entryTags[tag] = value;
}
entry.entryTags.type = entry.entryType;
@@ -60,11 +58,11 @@ export function parseBibtex(bibtex) {
export class Bibliography extends T(HTMLElement) {
constructor() {
super()
super();
// set up mutation observer
const options = {childList: true, subtree: true};
const observer = new MutationObserver( (mutations) => {
const options = {childList: true, characterData: true, subtree: true};
const observer = new MutationObserver( () => {
observer.disconnect();
this.parseIfPossible();
observer.observe(this, options);
@@ -82,27 +80,10 @@ export class Bibliography extends T(HTMLElement) {
this.notify(bibliography);
}
}
};
}
connectedCallback() {
this.list = this.root.querySelector('ol');
// bibliography is initially hidden
this.root.host.style.display = 'none';
// this.parseIfPossible();
// Store.subscribeTo('citations', (citations) => {
// // ensure citations list is visible
// this.root.host.style.display = 'initial';
// this.list.innerHTML = '';
// for (const key of citations) {
// const bibliography = Store.get('bibliography');
// const entry = bibliography.get(key);
// // construct and append list item to show citation
// const listItem = document.createElement('li');
// listItem.id = key;
// listItem.innerHTML = bibliography_cite(entry);
// this.list.appendChild(listItem);
// }
// });
}
notify(bibliography) {
@@ -112,15 +93,20 @@ export class Bibliography extends T(HTMLElement) {
}
set entries(newEntries) {
this.root.host.style.display = 'initial';
this.list.innerHTML = '';
if (newEntries.size) {
this.root.host.style.display = 'initial';
this.list.innerHTML = '';
for (const [key, entry] of newEntries) {
const listItem = document.createElement('li');
listItem.id = key;
listItem.innerHTML = bibliography_cite(entry);
this.list.appendChild(listItem);
for (const [key, entry] of newEntries) {
const listItem = document.createElement('li');
listItem.id = key;
listItem.innerHTML = bibliography_cite(entry);
this.list.appendChild(listItem);
}
} else {
this.root.host.style.display = 'none';
}
}
renderContent() {
+12 -12
View File
@@ -1,7 +1,7 @@
import { Template } from "../mixins/template";
import { page } from "../helpers/layout";
import { Template } from '../mixins/template';
import { page } from '../helpers/layout';
const T = Template("d-byline", `
const T = Template('d-byline', `
<style>
d-byline {
box-sizing: border-box;
@@ -14,7 +14,7 @@ const T = Template("d-byline", `
padding-top: 20px;
padding-bottom: 20px;
}
${page(".byline")}
${page('.byline')}
d-article.centered {
text-align: center;
}
@@ -117,15 +117,15 @@ export function bylineTemplate(frontMatter) {
<div class="authors">
${frontMatter.authors.map( author => `<div class="author">
${author.personalURL ?
`<a class="name" href="${author.personalURL}">${author.name}</a>`
:
`<div class="name">${author.name}</div>`
}
`<a class="name" href="${author.personalURL}">${author.name}</a>`
:
`<div class="name">${author.name}</div>`
}
${author.affiliationURL ?
`<a class="affiliation" href="${author.affiliationURL}">${author.affiliation}</a>`
:
`<div class="affiliation">${author.affiliation}</div>`
}
`<a class="affiliation" href="${author.affiliationURL}">${author.affiliation}</a>`
:
`<div class="affiliation">${author.affiliation}</div>`
}
</div>`).join('\n')}
</div>
<div class="date">
+5 -5
View File
@@ -1,6 +1,6 @@
import { Template } from "../mixins/template";
import { hover_cite } from "../helpers/citation";
import { HoverBox } from "../helpers/hover-box";
import { Template } from '../mixins/template';
import { hover_cite } from '../helpers/citation';
import { HoverBox } from '../helpers/hover-box';
const T = Template('d-cite', `
<style>
@@ -54,7 +54,7 @@ export class Cite extends T(HTMLElement) {
/* Lifecycle */
constructor() {
super()
super();
// Cite.currentId += 1;
// this.citeId = Cite.currentId;
}
@@ -116,7 +116,7 @@ export class Cite extends T(HTMLElement) {
const numberStrings = numbers.map( index => {
return index == -1 ? '?' : index + 1 + '';
});
const textContent = "[" + numberStrings.join(", ") + "]";
const textContent = '[' + numberStrings.join(', ') + ']';
const innerSpan = this.root.querySelector('.citation-number');
innerSpan.textContent = textContent;
}
+14 -14
View File
@@ -1,12 +1,12 @@
import Prism from "prismjs";
import "prismjs/components/prism-python";
import "prismjs/components/prism-clike";
import css from "prismjs/themes/prism.css";
import Prism from 'prismjs';
import 'prismjs/components/prism-python';
import 'prismjs/components/prism-clike';
import css from 'prismjs/themes/prism.css';
import { Template } from "../mixins/template.js"
import { Mutating } from "../mixins/mutating.js"
import { Template } from '../mixins/template.js';
import { Mutating } from '../mixins/mutating.js';
const T = Template("d-code", `
const T = Template('d-code', `
<style>
code {
@@ -39,7 +39,7 @@ export class Code extends Mutating(T(HTMLElement)) {
// check if language can be highlighted
this.languageName = this.getAttribute('language');
if (!this.languageName) {
console.warn(`You need to provide a language attribute to your <d-code> block to let us know how to highlight your code; e.g.:\n <d-code language="python">zeros = np.zeros(shape)</d-code>.`);
console.warn('You need to provide a language attribute to your <d-code> block to let us know how to highlight your code; e.g.:\n <d-code language="python">zeros = np.zeros(shape)</d-code>.');
return;
}
const language = Prism.languages[this.languageName];
@@ -49,18 +49,18 @@ export class Code extends Mutating(T(HTMLElement)) {
}
let content = this.textContent;
const codeTag = this.shadowRoot.querySelector("#code-container");
const codeTag = this.shadowRoot.querySelector('#code-container');
if (this.hasAttribute("block")) {
if (this.hasAttribute('block')) {
// normalize the tab indents
content = content.replace(/\n/, "");
content = content.replace(/\n/, '');
const tabs = content.match(/\s*/);
content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
content = content.replace(new RegExp('\n' + tabs, 'g'), '\n');
content = content.trim();
// wrap code block in pre tag if needed
if (codeTag.parentNode instanceof ShadowRoot) {
const preTag = document.createElement("pre");
this.shadowRoot.removeChild(codeTag)
const preTag = document.createElement('pre');
this.shadowRoot.removeChild(codeTag);
preTag.appendChild(codeTag);
this.shadowRoot.appendChild(preTag);
}
+3 -3
View File
@@ -1,8 +1,8 @@
import { Template } from "../mixins/template.js";
import { HoverBox } from "../helpers/hover-box";
import { Template } from '../mixins/template.js';
import { HoverBox } from '../helpers/hover-box';
// import { Store } from './store';
const T = Template("d-footnote", `
const T = Template('d-footnote', `
<style>
d-math[block] {
+5 -5
View File
@@ -1,14 +1,14 @@
import ymlParse from "js-yaml";
import ymlParse from 'js-yaml';
export class FrontMatter extends HTMLElement {
static get is() { return "d-front-matter"; }
static get is() { return 'd-front-matter'; }
constructor() {
super();
const options = {childList: true, characterData: true, subtree: true};
const observer = new MutationObserver( (mutation) => {
const observer = new MutationObserver( () => {
const data = this.parse();
this.notify(data);
});
@@ -16,13 +16,13 @@ export class FrontMatter extends HTMLElement {
}
parse(){
const scriptTag = this.querySelector("script");
const scriptTag = this.querySelector('script');
if (scriptTag) {
const yml = scriptTag.textContent;
const data = ymlParse.safeLoad(yml);
return data;
} else {
console.error('You added a frontmatter tag but did not provide a script tag with front matter data in it. Please take a look at our templates.')
console.error('You added a frontmatter tag but did not provide a script tag with front matter data in it. Please take a look at our templates.');
return {};
}
}
+7 -7
View File
@@ -1,9 +1,9 @@
import katex from "katex";
import { Mutating } from "../mixins/mutating.js"
import { Template } from "../mixins/template.js"
import katexCSS from "../../node_modules/katex/dist/katex.min.css"
import katex from 'katex';
import { Mutating } from '../mixins/mutating.js';
import { Template } from '../mixins/template.js';
import katexCSS from '../../node_modules/katex/dist/katex.min.css';
const T = Template("d-math", `
const T = Template('d-math', `
<style>
d-math[block] {
@@ -20,8 +20,8 @@ ${katexCSS}
export class DMath extends Mutating(T(HTMLElement)) {
renderContent() {
const options = { displayMode: this.hasAttribute("block") };
const container = this.root.querySelector("#katex-container");
const options = { displayMode: this.hasAttribute('block') };
const container = this.root.querySelector('#katex-container');
katex.render(this.textContent, container, options);
}
+2 -3
View File
@@ -1,7 +1,6 @@
import { Template } from "../mixins/template";
import { body } from "../helpers/layout";
import { Template } from '../mixins/template';
const T = Template("d-references", `
const T = Template('d-references', `
<style>
d-references {
display: block;
+4 -4
View File
@@ -1,7 +1,7 @@
import { Template } from "../mixins/template";
import { page } from "../helpers/layout";
import { Template } from '../mixins/template';
import { page } from '../helpers/layout';
const T = Template("d-title", `
const T = Template('d-title', `
<style>
:host {
@@ -24,7 +24,7 @@ d-byline {
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
${page("::slotted(h1), ::slotted(h2)")}
${page('::slotted(h1), ::slotted(h2)')}
</style>
+2 -2
View File
@@ -1,6 +1,6 @@
import {Template} from "../mixins/template";
import {Template} from '../mixins/template';
const T = Template("d-toc", `
const T = Template('d-toc', `
<style>
d-toc {
display: block;
+2 -2
View File
@@ -29,7 +29,7 @@ const styles = `
margin-top: -12px;
}
</style>
`
`;
export function appendixTemplate(frontMatter) {
return `
@@ -57,7 +57,7 @@ export function appendixTemplate(frontMatter) {
export class DistillAppendix extends HTMLElement {
static get is() { return "distill-appendix"; }
static get is() { return 'distill-appendix'; }
set frontMatter(frontMatter) {
this.innerHTML = appendixTemplate(frontMatter);
+4 -4
View File
@@ -1,9 +1,9 @@
import {Template} from "../mixins/template";
import {Template} from '../mixins/template';
// import logo from "./distill-logo.svg";
var logo = "";
var logo = '';
const T = Template("distill-header", `
const T = Template('distill-header', `
<style>
:host {
box-sizing: border-box;
@@ -86,6 +86,6 @@ svg path {
export class DistillHeader extends T(HTMLElement) {
static get is() {
return "distill-header";
return 'distill-header';
}
}
+18 -22
View File
@@ -1,8 +1,8 @@
import {timeFormat} from "d3-time-format";
import {timeFormat} from 'd3-time-format';
const zeroPad = n => n < 10 ? "0" + n : n;
const RFC = timeFormat("%a, %d %b %Y %H:%M:%S %Z");
const months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
const zeroPad = n => n < 10 ? '0' + n : n;
const RFC = timeFormat('%a, %d %b %Y %H:%M:%S %Z');
const months = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
class Author {
@@ -15,21 +15,21 @@ class Author {
// "Chris"
get firstName() {
const names = this.name.split(" ");
return names.slice(0, names.length - 1).join(" ");
const names = this.name.split(' ');
return names.slice(0, names.length - 1).join(' ');
}
// "Olah"
get lastName() {
const names = this.name.split(" ");
const names = this.name.split(' ');
return names[names.length -1];
}
}
export class FrontMatter {
constructor() {
this.title = ""; // "Attention and Augmented Recurrent Neural Networks"
this.description = ""; // "A visual overview of neural attention..."
this.title = ''; // "Attention and Augmented Recurrent Neural Networks"
this.description = ''; // "A visual overview of neural attention..."
this.authors = []; // Array of Author(s)
this.bibliography = new Map();
@@ -111,7 +111,7 @@ export class FrontMatter {
}
author.affiliation = Object.keys(affiliationEntry)[0];
if (typeof affiliationEntry === 'object') {
author.affiliationURL = affiliationEntry[author.affiliation]
author.affiliationURL = affiliationEntry[author.affiliation];
}
return author;
});
@@ -127,9 +127,9 @@ export class FrontMatter {
}
get url() {
if (this._url) {
return this._url
return this._url;
} else if (this.distillPath && this.journal.url) {
return this.journal.url + "/" + this.distillPath;
return this.journal.url + '/' + this.distillPath;
} else if (this.journal.url) {
return this.journal.url;
}
@@ -137,7 +137,7 @@ export class FrontMatter {
// 'https://github.com/distillpub/post--augmented-rnns',
get githubUrl() {
return "https://github.com/" + this.githubPath;
return 'https://github.com/' + this.githubPath;
}
// TODO resolve differences in naming of URL/Url/url.
@@ -146,7 +146,7 @@ export class FrontMatter {
this._previewURL = value;
}
get previewURL() {
return this._previewURL ? this._previewURL : this.url + "/thumbnail.jpg";
return this._previewURL ? this._previewURL : this.url + '/thumbnail.jpg';
}
// 'Thu, 08 Sep 2016 00:00:00 -0700',
@@ -184,16 +184,12 @@ export class FrontMatter {
return zeroPad(this.publishedDate.getDate());
}
// 'Tue, 21 Mar 2017 00:13:16 -0700',
get updatedDateRFC() {
}
// 'Olah & Carter',
get concatenatedAuthors() {
if (this.authors.length > 2) {
return this.authors[0].lastName + ", et al.";
return this.authors[0].lastName + ', et al.';
} else if (this.authors.length === 2) {
return this.authors[0].lastName + " & " + this.authors[1].lastName;
return this.authors[0].lastName + ' & ' + this.authors[1].lastName;
} else if (this.authors.length === 1) {
return this.authors[0].lastName;
}
@@ -202,8 +198,8 @@ export class FrontMatter {
// 'Olah, Chris and Carter, Shan',
get bibtexAuthors() {
return this.authors.map(author => {
return author.lastName + ", " + author.firstName
}).join(" and ");
return author.lastName + ', ' + author.firstName;
}).join(' and ');
}
// 'olah2016attention'
+61 -61
View File
@@ -2,50 +2,50 @@ export function inline_cite_short(keys){
function cite_string(key){
if (key in data.bibliography){
var n = data.citations.indexOf(key)+1;
return ""+n;
return ''+n;
} else {
return "?";
return '?';
}
}
return "["+keys.map(cite_string).join(", ")+"]";
return '['+keys.map(cite_string).join(', ')+']';
}
export function inline_cite_long(keys){
function cite_string(key){
if (key in data.bibliography){
var ent = data.bibliography[key];
var names = ent.author.split(" and ");
names = names.map(name => name.split(",")[0].trim())
var names = ent.author.split(' and ');
names = names.map(name => name.split(',')[0].trim());
var year = ent.year;
if (names.length == 1) return names[0] + ", " + year;
if (names.length == 2) return names[0] + " & " + names[1] + ", " + year;
if (names.length > 2) return names[0] + ", et al., " + year;
if (names.length == 1) return names[0] + ', ' + year;
if (names.length == 2) return names[0] + ' & ' + names[1] + ', ' + year;
if (names.length > 2) return names[0] + ', et al., ' + year;
} else {
return "?";
return '?';
}
}
return keys.map(cite_string).join(", ");
return keys.map(cite_string).join(', ');
}
function author_string(ent, template, sep, finalSep){
var names = ent.author.split(" and ");
var names = ent.author.split(' and ');
let name_strings = names.map(name => {
name = name.trim();
if (name.indexOf(",") != -1){
var last = name.split(",")[0].trim();
var firsts = name.split(",")[1];
if (name.indexOf(',') != -1){
var last = name.split(',')[0].trim();
var firsts = name.split(',')[1];
} else {
var last = name.split(" ").slice(-1)[0].trim();
var firsts = name.split(" ").slice(0,-1).join(" ");
var last = name.split(' ').slice(-1)[0].trim();
var firsts = name.split(' ').slice(0,-1).join(' ');
}
var initials = "";
var initials = '';
if (firsts != undefined) {
initials = firsts.trim().split(" ").map(s => s.trim()[0]);
initials = initials.join(".")+".";
initials = firsts.trim().split(' ').map(s => s.trim()[0]);
initials = initials.join('.')+'.';
}
return template.replace("${F}", firsts)
.replace("${L}", last)
.replace("${I}", initials);
return template.replace('${F}', firsts)
.replace('${L}', last)
.replace('${I}', initials);
});
if (names.length > 1) {
var str = name_strings.slice(0, names.length-1).join(sep);
@@ -57,64 +57,64 @@ function author_string(ent, template, sep, finalSep){
}
function venue_string(ent) {
var cite = (ent.journal || ent.booktitle || "")
if ("volume" in ent){
var cite = (ent.journal || ent.booktitle || '');
if ('volume' in ent){
var issue = ent.issue || ent.number;
issue = (issue != undefined)? "("+issue+")" : "";
cite += ", Vol " + ent.volume + issue;
issue = (issue != undefined)? '('+issue+')' : '';
cite += ', Vol ' + ent.volume + issue;
}
if ("pages" in ent){
cite += ", pp. " + ent.pages
if ('pages' in ent){
cite += ', pp. ' + ent.pages;
}
if (cite != "") cite += ". "
if ("publisher" in ent){
if (cite != '') cite += '. ';
if ('publisher' in ent){
cite += ent.publisher;
if (cite[cite.length-1] != ".") cite += ".";
if (cite[cite.length-1] != '.') cite += '.';
}
return cite;
}
function link_string(ent){
if ("url" in ent){
if ('url' in ent){
var url = ent.url;
var arxiv_match = (/arxiv\.org\/abs\/([0-9\.]*)/).exec(url);
if (arxiv_match != null){
url = `http://arxiv.org/pdf/${arxiv_match[1]}.pdf`;
}
if (url.slice(-4) == ".pdf"){
var label = "PDF";
} else if (url.slice(-5) == ".html") {
var label = "HTML";
if (url.slice(-4) == '.pdf'){
var label = 'PDF';
} else if (url.slice(-5) == '.html') {
var label = 'HTML';
}
return ` &ensp;<a href="${url}">[${label||"link"}]</a>`;
return ` &ensp;<a href="${url}">[${label||'link'}]</a>`;
}/* else if ("doi" in ent){
return ` &ensp;<a href="https://doi.org/${ent.doi}" >[DOI]</a>`;
}*/ else {
return "";
return '';
}
}
function doi_string(ent, new_line){
if ("doi" in ent) {
return `${new_line?"<br>":""} <a href="https://doi.org/${ent.doi}" style="text-decoration:inherit;">DOI: ${ent.doi}</a>`;
if ('doi' in ent) {
return `${new_line?'<br>':''} <a href="https://doi.org/${ent.doi}" style="text-decoration:inherit;">DOI: ${ent.doi}</a>`;
} else {
return "";
return '';
}
}
export function bibliography_cite(ent, fancy){
if (ent){
var cite = "<b>" + ent.title + "</b> "
cite += link_string(ent) + "<br>";
cite += author_string(ent, "${L}, ${I}", ", ", " and ");
var cite = '<b>' + ent.title + '</b> ';
cite += link_string(ent) + '<br>';
cite += author_string(ent, '${L}, ${I}', ', ', ' and ');
if (ent.year || ent.date){
cite += ", " + (ent.year || ent.date) + ". "
cite += ', ' + (ent.year || ent.date) + '. ';
} else {
cite += ". "
cite += '. ';
}
cite += venue_string(ent);
cite += doi_string(ent);
return cite
return cite;
/*var cite = author_string(ent, "${L}, ${I}", ", ", " and ");
if (ent.year || ent.date){
cite += ", " + (ent.year || ent.date) + ". "
@@ -127,28 +127,28 @@ export function bibliography_cite(ent, fancy){
cite += link_string(ent);
return cite*/
} else {
return "?";
return '?';
}
}
export function hover_cite(ent){
if (ent){
var cite = "";
cite += "<b>" + ent.title + "</b>";
var cite = '';
cite += '<b>' + ent.title + '</b>';
cite += link_string(ent);
cite += "<br>"
cite += '<br>';
var a_str = author_string(ent, "${I} ${L}", ", ") + ".";
var v_str = venue_string(ent).trim() + " " + ent.year + ". " + doi_string(ent, true);
var a_str = author_string(ent, '${I} ${L}', ', ') + '.';
var v_str = venue_string(ent).trim() + ' ' + ent.year + '. ' + doi_string(ent, true);
if ((a_str+v_str).length < Math.min(40, ent.title.length)) {
cite += a_str + " " + v_str;
cite += a_str + ' ' + v_str;
} else {
cite += a_str + "<br>" + v_str;
cite += a_str + '<br>' + v_str;
}
return cite;
} else {
return "?";
return '?';
}
}
@@ -156,10 +156,10 @@ export function hover_cite(ent){
//https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah
function get_GS_URL(ent){
if (ent){
var names = ent.author.split(" and ");
names = names.map(name => name.split(",")[0].trim())
var title = ent.title.split(" ")//.replace(/[,:]/, "")
var url = "http://search.labs.crossref.org/dois?"//""https://scholar.google.com/scholar?"
url += uris({q: names.join(" ") + " " + title.join(" ")})
var names = ent.author.split(' and ');
names = names.map(name => name.split(',')[0].trim());
var title = ent.title.split(' ');//.replace(/[,:]/, "")
var url = 'http://search.labs.crossref.org/dois?';//""https://scholar.google.com/scholar?"
url += uris({q: names.join(' ') + ' ' + title.join(' ')});
}
}
+21 -21
View File
@@ -2,7 +2,7 @@ function make_hover_css(pos) {
var pretty = window.innerWidth > 600;
var padding = pretty? 18 : 12;
var outer_padding = pretty ? 18 : 0;
var bbox = document.querySelector("body").getBoundingClientRect();
var bbox = document.querySelector('body').getBoundingClientRect();
var left = pos[0] - bbox.left, top = pos[1] - bbox.top;
var width = Math.min(window.innerWidth-2*outer_padding, 648);
left = Math.min(left, window.innerWidth-width-outer_padding);
@@ -40,53 +40,53 @@ HoverBox.get_box = function get_box(div_id) {
} else {
return new HoverBox(div_id);
}
}
};
HoverBox.prototype.show = function show(pos){
this.visible = true;
this.div.setAttribute("style", make_hover_css(pos) );
this.div.setAttribute('style', make_hover_css(pos) );
for (var box_id in HoverBox.box_map) {
var box = HoverBox.box_map[box_id];
if (box != this) box.hide();
}
}
};
HoverBox.prototype.showAtNode = function showAtNode(node){
var bbox = node.getBoundingClientRect();
this.show([bbox.right, bbox.bottom]);
}
var bbox = node.getBoundingClientRect();
this.show([bbox.right, bbox.bottom]);
};
HoverBox.prototype.hide = function hide(){
this.visible = false;
if (this.div) this.div.setAttribute("style", "display:none");
if (this.div) this.div.setAttribute('style', 'display:none');
if (this.timeout) clearTimeout(this.timeout);
}
};
HoverBox.prototype.stopTimeout = function stopTimeout() {
if (this.timeout) clearTimeout(this.timeout);
}
};
HoverBox.prototype.extendTimeout = function extendTimeout(T) {
//console.log("extend", T)
var this_ = this;
this.stopTimeout();
this.timeout = setTimeout(function(){this_.hide();}.bind(this), T);
}
};
// Bind events to a link to open this box
HoverBox.prototype.bind = function bind(node) {
if (typeof node == "string"){
if (typeof node == 'string'){
node = document.querySelector(node);
}
node.addEventListener("mouseover", function(){
node.addEventListener('mouseover', function(){
if (!this.visible) this.showAtNode(node);
this.stopTimeout();
}.bind(this));
node.addEventListener("mouseout", function(){this.extendTimeout(250);}.bind(this));
node.addEventListener('mouseout', function(){this.extendTimeout(250);}.bind(this));
node.addEventListener("touchstart", function(e) {
node.addEventListener('touchstart', function(e) {
if (this.visible) {
this.hide();
} else {
@@ -95,18 +95,18 @@ HoverBox.prototype.bind = function bind(node) {
// Don't trigger body touchstart event when touching link
e.stopPropagation();
}.bind(this), {passive: true});
}
};
HoverBox.prototype.bindDivEvents = function bindDivEvents(node){
// For mice, same behavior as hovering on links
this.div.addEventListener("mouseover", function(){
this.div.addEventListener('mouseover', function(){
if (!this.visible) this.showAtNode(node);
this.stopTimeout();
}.bind(this));
this.div.addEventListener("mouseout", function(){this.extendTimeout(250);}.bind(this));
this.div.addEventListener('mouseout', function(){this.extendTimeout(250);}.bind(this));
// Don't trigger body touchstart event when touching within box
this.div.addEventListener("touchstart", function(e){e.stopPropagation();}, {passive: true});
this.div.addEventListener('touchstart', function(e){e.stopPropagation();}, {passive: true});
// Close box when touching outside box
document.body.addEventListener("touchstart", function(){this.hide();}.bind(this), {passive: true});
}
document.body.addEventListener('touchstart', function(){this.hide();}.bind(this), {passive: true});
};
+3 -4
View File
@@ -1,4 +1,3 @@
export const Mutating = (superclass) => {
return class extends superclass {
@@ -7,7 +6,7 @@ export const Mutating = (superclass) => {
// set up mutation observer
const options = {childList: true, characterData: true, subtree: true};
const observer = new MutationObserver( (mutations) => {
const observer = new MutationObserver( () => {
observer.disconnect();
this.renderIfPossible();
observer.observe(this, options);
@@ -29,11 +28,11 @@ export const Mutating = (superclass) => {
if (this.textContent && this.root) {
this.renderContent();
}
};
}
renderContent() {
console.error(`Your class ${this.constructor.name} must provide a custom renderContent() method!` );
}
} // end class
}; // end class
}; // end mixin function
+15 -16
View File
@@ -1,5 +1,5 @@
export function propName(attr) {
return attr.replace(/(\-[a-z])/g, (s) => s.toUpperCase().replace('-', ''));
return attr.replace(/(-[a-z])/g, (s) => s.toUpperCase().replace('-', ''));
}
export function attrName(prop) {
@@ -8,19 +8,18 @@ export function attrName(prop) {
export function deserializeAttribute(value, type) {
switch (type) {
case String:
break;
case Array:
case Object:
try {
value = JSON.parse(value);
} catch (e) {
}
break;
case Boolean:
value = value != 'false' && value != '0' && value;
break;
default:
case String:
break;
case Array:
case Object:
try {
value = JSON.parse(value);
} catch (e) {}
break;
case Boolean:
value = value != 'false' && value != '0' && value;
break;
default:
}
return value;
}
@@ -53,7 +52,7 @@ export const Properties = (properties) => {
this.propertiesChangedCallback(this);
});
}
}
};
keys.forEach(function(k) {
const secret = `_${k}`;
const callback = `${k}Changed`;
@@ -83,4 +82,4 @@ export const Properties = (properties) => {
});
return cls;
};
};
};
+4 -2
View File
@@ -1,3 +1,5 @@
/*global ShadyCSS*/
export const Template = (name, templateString, useShadow = true) => {
const template = document.createElement('template');
@@ -48,6 +50,6 @@ export const Template = (name, templateString, useShadow = true) => {
$$(query) {
return this.root.querySelectorAll(query);
}
}
}
};
};
};
+7 -7
View File
@@ -1,10 +1,10 @@
import base from "./styles-base.css";
import layout from "./styles-layout.css";
import article from "./styles-article.css";
import print from "./styles-print.css";
import katex from '../../node_modules/katex/dist/katex.min.css'
import base from './styles-base.css';
import layout from './styles-layout.css';
import article from './styles-article.css';
import print from './styles-print.css';
import katex from '../../node_modules/katex/dist/katex.min.css';
let s = document.createElement("style");
let s = document.createElement('style');
s.textContent = base + layout + print + article + katex;
document.querySelector("head").appendChild(s);
document.querySelector('head').appendChild(s);
export default s;
+15 -15
View File
@@ -58,14 +58,14 @@ const html = `
`;
export default function(dom, data) {
let el = dom.querySelector('dt-appendix')
let el = dom.querySelector('dt-appendix');
if (el) {
let oldHtml = el.innerHTML;
el.innerHTML = html;
let div = el.querySelector("div.l-body")
let div = el.querySelector('div.l-body');
if (dom.querySelector("dt-fn")) {
div.innerHTML = `<h3>Footnotes</h3><dt-fn-list></dt-fn-list>` + div.innerHTML;
if (dom.querySelector('dt-fn')) {
div.innerHTML = '<h3>Footnotes</h3><dt-fn-list></dt-fn-list>' + div.innerHTML;
}
div.innerHTML = oldHtml + div.innerHTML;
@@ -73,17 +73,17 @@ export default function(dom, data) {
div.innerHTML = `<h3>Updates</h3><p><a href="${data.githubCompareUpdatesUrl}">View all changes</a> to this article since it was first published.</p>` + div.innerHTML;
}
el.querySelector("a.github").setAttribute("href", data.githubUrl);
el.querySelector("a.github-issue").setAttribute("href", data.githubUrl + "/issues/new");
el.querySelector(".citation.short").textContent = data.concatenatedAuthors + ", " + '"' + data.title + '", Distill, ' + data.publishedYear + ".";
var bibtex = "@article{" + data.slug + ",\n";
bibtex += " author = {" + data.bibtexAuthors + "},\n";
bibtex += " title = {" + data.title + "},\n";
bibtex += " journal = {Distill},\n";
bibtex += " year = {" + data.publishedYear + "},\n";
bibtex += " note = {" + data.url + "}\n";
bibtex += "}";
el.querySelector(".citation.long").textContent = bibtex;
el.querySelector('a.github').setAttribute('href', data.githubUrl);
el.querySelector('a.github-issue').setAttribute('href', data.githubUrl + '/issues/new');
el.querySelector('.citation.short').textContent = data.concatenatedAuthors + ', ' + '"' + data.title + '", Distill, ' + data.publishedYear + '.';
var bibtex = '@article{' + data.slug + ',\n';
bibtex += ' author = {' + data.bibtexAuthors + '},\n';
bibtex += ' title = {' + data.title + '},\n';
bibtex += ' journal = {Distill},\n';
bibtex += ' year = {' + data.publishedYear + '},\n';
bibtex += ' note = {' + data.url + '}\n';
bibtex += '}';
el.querySelector('.citation.long').textContent = bibtex;
}
}
+4 -4
View File
@@ -13,11 +13,11 @@ const html = `
`;
export default function(dom, data) {
let banner = dom.createElement("dt-banner");
let banner = dom.createElement('dt-banner');
banner.innerHTML = html;
let b = dom.querySelector("body");
let b = dom.querySelector('body');
b.insertBefore(banner, b.firstChild);
banner.addEventListener("click", function() {
banner.style.display = "none";
banner.addEventListener('click', function() {
banner.style.display = 'none';
});
}
+9 -9
View File
@@ -1,4 +1,4 @@
import bibtexParse from "bibtex-parse-js";
import bibtexParse from 'bibtex-parse-js';
export default function(dom, data) {
let el = dom.querySelector('script[type="text/bibliography"]');
@@ -12,11 +12,11 @@ export default function(dom, data) {
parsed.forEach(e => {
for (var k in e.entryTags){
var val = e.entryTags[k];
val = val.replace(/[\t\n ]+/g, " ");
val = val.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g,
(full, x, char) => char);
val = val.replace(/[\t\n ]+/g, ' ');
val = val.replace(/{\\["^`.'acu~Hvs]( )?([a-zA-Z])}/g,
(full, x, char) => char);
val = val.replace(/{\\([a-zA-Z])}/g,
(full, char) => char);
(full, char) => char);
e.entryTags[k] = val;
}
bibliography[e.citationKey] = e.entryTags;
@@ -25,16 +25,16 @@ export default function(dom, data) {
}
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
var citeTags = [].slice.apply(dom.querySelectorAll('dt-cite'));
citeTags.forEach(el => {
let key = el.getAttribute("key");
let key = el.getAttribute('key');
if (key) {
let citationKeys = key.split(",");
let citationKeys = key.split(',');
citationKeys.forEach(key => {
if (citations.indexOf(key) == -1){
citations.push(key);
if (!(key in bibliography)){
console.warn("No bibliography entry found for: " + key);
console.warn('No bibliography entry found for: ' + key);
}
}
});
+2 -2
View File
@@ -1,4 +1,4 @@
import mustache from "mustache";
import mustache from 'mustache';
const html = `
<style>
@@ -145,7 +145,7 @@ const template = `
<div>{{concatenatedAuthors}}, {{publishedYear}}</div>
</a>
</div>
`
`;
export default function(dom, data) {
let el = dom.querySelector('dt-byline');
+74 -74
View File
@@ -24,9 +24,9 @@ export default function(dom, data) {
}
`;
let style = dom.createElement("style");
let style = dom.createElement('style');
style.textContent = css;
dom.querySelector("body").appendChild(style);
dom.querySelector('body').appendChild(style);
let citations = data.citations;
/*if (data.citations) {
@@ -36,32 +36,32 @@ export default function(dom, data) {
});
}*/
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
var citeTags = [].slice.apply(dom.querySelectorAll('dt-cite'));
citeTags.forEach((el,n) => {
var key = el.getAttribute("key");
var key = el.getAttribute('key');
if (key) {
var keys = key.split(",");
var keys = key.split(',');
var cite_string = inline_cite_short(keys);
var cite_hover_str = "";
var cite_hover_str = '';
keys.map((key,n) => {
if (n>0) cite_hover_str += "<br><br>";
if (n>0) cite_hover_str += '<br><br>';
cite_hover_str += hover_cite(data.bibliography[key]);
});
cite_hover_str = cite_hover_str.replace(/"/g, "&#39;")
cite_hover_str = cite_hover_str.replace(/"/g, '&#39;');
var orig_string = el.innerHTML;
if (orig_string != "") orig_string += " ";
if (orig_string != '') orig_string += ' ';
el.innerHTML = `<span id="citation-${n}" data-hover="${cite_hover_str}">${orig_string}<span class="citation-number">${cite_string}</span></span>`;
}
});
let bibEl = dom.querySelector("dt-bibliography");
let bibEl = dom.querySelector('dt-bibliography');
if (bibEl) {
let ol = dom.createElement("ol");
let ol = dom.createElement('ol');
citations.forEach(key => {
let el = dom.createElement("li");
let el = dom.createElement('li');
el.innerHTML = bibliography_cite(data.bibliography[key]);
ol.appendChild(el);
})
});
bibEl.appendChild(ol);
}
@@ -69,50 +69,50 @@ export default function(dom, data) {
function cite_string(key){
if (key in data.bibliography){
var n = data.citations.indexOf(key)+1;
return ""+n;
return ''+n;
} else {
return "?";
return '?';
}
}
return "["+keys.map(cite_string).join(", ")+"]";
return '['+keys.map(cite_string).join(', ')+']';
}
function inline_cite_long(keys){
function cite_string(key){
if (key in data.bibliography){
var ent = data.bibliography[key];
var names = ent.author.split(" and ");
names = names.map(name => name.split(",")[0].trim())
var names = ent.author.split(' and ');
names = names.map(name => name.split(',')[0].trim());
var year = ent.year;
if (names.length == 1) return names[0] + ", " + year;
if (names.length == 2) return names[0] + " & " + names[1] + ", " + year;
if (names.length > 2) return names[0] + ", et al., " + year;
if (names.length == 1) return names[0] + ', ' + year;
if (names.length == 2) return names[0] + ' & ' + names[1] + ', ' + year;
if (names.length > 2) return names[0] + ', et al., ' + year;
} else {
return "?";
return '?';
}
}
return keys.map(cite_string).join(", ");
return keys.map(cite_string).join(', ');
}
function author_string(ent, template, sep, finalSep){
var names = ent.author.split(" and ");
var names = ent.author.split(' and ');
let name_strings = names.map(name => {
name = name.trim();
if (name.indexOf(",") != -1){
var last = name.split(",")[0].trim();
var firsts = name.split(",")[1];
if (name.indexOf(',') != -1){
var last = name.split(',')[0].trim();
var firsts = name.split(',')[1];
} else {
var last = name.split(" ").slice(-1)[0].trim();
var firsts = name.split(" ").slice(0,-1).join(" ");
var last = name.split(' ').slice(-1)[0].trim();
var firsts = name.split(' ').slice(0,-1).join(' ');
}
var initials = "";
var initials = '';
if (firsts != undefined) {
initials = firsts.trim().split(" ").map(s => s.trim()[0]);
initials = initials.join(".")+".";
initials = firsts.trim().split(' ').map(s => s.trim()[0]);
initials = initials.join('.')+'.';
}
return template.replace("${F}", firsts)
.replace("${L}", last)
.replace("${I}", initials);
return template.replace('${F}', firsts)
.replace('${L}', last)
.replace('${I}', initials);
});
if (names.length > 1) {
var str = name_strings.slice(0, names.length-1).join(sep);
@@ -124,64 +124,64 @@ export default function(dom, data) {
}
function venue_string(ent) {
var cite = (ent.journal || ent.booktitle || "")
if ("volume" in ent){
var cite = (ent.journal || ent.booktitle || '');
if ('volume' in ent){
var issue = ent.issue || ent.number;
issue = (issue != undefined)? "("+issue+")" : "";
cite += ", Vol " + ent.volume + issue;
issue = (issue != undefined)? '('+issue+')' : '';
cite += ', Vol ' + ent.volume + issue;
}
if ("pages" in ent){
cite += ", pp. " + ent.pages
if ('pages' in ent){
cite += ', pp. ' + ent.pages;
}
if (cite != "") cite += ". "
if ("publisher" in ent){
if (cite != '') cite += '. ';
if ('publisher' in ent){
cite += ent.publisher;
if (cite[cite.length-1] != ".") cite += ".";
if (cite[cite.length-1] != '.') cite += '.';
}
return cite;
}
function link_string(ent){
if ("url" in ent){
if ('url' in ent){
var url = ent.url;
var arxiv_match = (/arxiv\.org\/abs\/([0-9\.]*)/).exec(url);
if (arxiv_match != null){
url = `http://arxiv.org/pdf/${arxiv_match[1]}.pdf`;
}
if (url.slice(-4) == ".pdf"){
var label = "PDF";
} else if (url.slice(-5) == ".html") {
var label = "HTML";
if (url.slice(-4) == '.pdf'){
var label = 'PDF';
} else if (url.slice(-5) == '.html') {
var label = 'HTML';
}
return ` &ensp;<a href="${url}">[${label||"link"}]</a>`;
return ` &ensp;<a href="${url}">[${label||'link'}]</a>`;
}/* else if ("doi" in ent){
return ` &ensp;<a href="https://doi.org/${ent.doi}" >[DOI]</a>`;
}*/ else {
return "";
return '';
}
}
function doi_string(ent, new_line){
if ("doi" in ent) {
return `${new_line?"<br>":""} <a href="https://doi.org/${ent.doi}" style="text-decoration:inherit;">DOI: ${ent.doi}</a>`;
if ('doi' in ent) {
return `${new_line?'<br>':''} <a href="https://doi.org/${ent.doi}" style="text-decoration:inherit;">DOI: ${ent.doi}</a>`;
} else {
return "";
return '';
}
}
function bibliography_cite(ent, fancy){
if (ent){
var cite = "<b>" + ent.title + "</b> "
cite += link_string(ent) + "<br>";
cite += author_string(ent, "${L}, ${I}", ", ", " and ");
var cite = '<b>' + ent.title + '</b> ';
cite += link_string(ent) + '<br>';
cite += author_string(ent, '${L}, ${I}', ', ', ' and ');
if (ent.year || ent.date){
cite += ", " + (ent.year || ent.date) + ". "
cite += ', ' + (ent.year || ent.date) + '. ';
} else {
cite += ". "
cite += '. ';
}
cite += venue_string(ent);
cite += doi_string(ent);
return cite
return cite;
/*var cite = author_string(ent, "${L}, ${I}", ", ", " and ");
if (ent.year || ent.date){
cite += ", " + (ent.year || ent.date) + ". "
@@ -194,28 +194,28 @@ export default function(dom, data) {
cite += link_string(ent);
return cite*/
} else {
return "?";
return '?';
}
}
function hover_cite(ent){
if (ent){
var cite = "";
cite += "<b>" + ent.title + "</b>";
var cite = '';
cite += '<b>' + ent.title + '</b>';
cite += link_string(ent);
cite += "<br>"
cite += '<br>';
var a_str = author_string(ent, "${I} ${L}", ", ") + ".";
var v_str = venue_string(ent).trim() + " " + ent.year + ". " + doi_string(ent, true);
var a_str = author_string(ent, '${I} ${L}', ', ') + '.';
var v_str = venue_string(ent).trim() + ' ' + ent.year + '. ' + doi_string(ent, true);
if ((a_str+v_str).length < Math.min(40, ent.title.length)) {
cite += a_str + " " + v_str;
cite += a_str + ' ' + v_str;
} else {
cite += a_str + "<br>" + v_str;
cite += a_str + '<br>' + v_str;
}
return cite;
} else {
return "?";
return '?';
}
}
@@ -223,11 +223,11 @@ export default function(dom, data) {
//https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah
function get_GS_URL(ent){
if (ent){
var names = ent.author.split(" and ");
names = names.map(name => name.split(",")[0].trim())
var title = ent.title.split(" ")//.replace(/[,:]/, "")
var url = "http://search.labs.crossref.org/dois?"//""https://scholar.google.com/scholar?"
url += uris({q: names.join(" ") + " " + title.join(" ")})
var names = ent.author.split(' and ');
names = names.map(name => name.split(',')[0].trim());
var title = ent.title.split(' ');//.replace(/[,:]/, "")
var url = 'http://search.labs.crossref.org/dois?';//""https://scholar.google.com/scholar?"
url += uris({q: names.join(' ') + ' ' + title.join(' ')});
}
}
+10 -10
View File
@@ -1,19 +1,19 @@
import Prism from "prismjs";
import Prism from 'prismjs';
export default function(dom, data) {
let codeElements = [].slice.call(dom.querySelectorAll("dt-code"));
let codeElements = [].slice.call(dom.querySelectorAll('dt-code'));
codeElements.forEach(el => {
let content = el.textContent;
el.innerHTML = "";
let language = el.getAttribute("language");
let c = dom.createElement("code");
if (el.getAttribute("block") === "") {
el.innerHTML = '';
let language = el.getAttribute('language');
let c = dom.createElement('code');
if (el.getAttribute('block') === '') {
// Let's normalize the tab indents
content = content.replace(/\n/, "");
content = content.replace(/\n/, '');
let tabs = content.match(/\s*/);
content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
content = content.replace(new RegExp('\n' + tabs, 'g'), '\n');
content = content.trim();
let p = dom.createElement("pre");
let p = dom.createElement('pre');
p.appendChild(c);
el.appendChild(p);
} else {
@@ -21,7 +21,7 @@ export default function(dom, data) {
}
let highlighted = content;
if (Prism.languages[language]) {
c.setAttribute("class", "language-" + language);
c.setAttribute('class', 'language-' + language);
highlighted = Prism.highlight(content, Prism.languages[language]);
}
c.innerHTML = highlighted;
+4 -4
View File
@@ -1,4 +1,4 @@
import logo from "./distill-logo.svg";
import logo from './distill-logo.svg';
let html = `
<style>
@@ -40,13 +40,13 @@ dt-footer .logo {
`;
export default function(dom, data) {
let el = dom.querySelector("dt-footer");
let el = dom.querySelector('dt-footer');
if(el) {
el.innerHTML = html;
} else {
let footer = dom.createElement("dt-footer");
let footer = dom.createElement('dt-footer');
footer.innerHTML = html;
let b = dom.querySelector("body");
let b = dom.querySelector('body');
b.appendChild(footer);
}
}
+8 -8
View File
@@ -1,24 +1,24 @@
export default function(dom, data) {
var fnTags = [].slice.apply(dom.querySelectorAll("dt-fn"));
var fnTags = [].slice.apply(dom.querySelectorAll('dt-fn'));
var fnContent = [];
fnTags.forEach((el,n) => {
var content = el.innerHTML;
fnContent.push(content);
n = (n+1)+"";
var key = "fn-"+n;
var escaped_content = content.replace(/"/g, "&#39;");
n = (n+1)+'';
var key = 'fn-'+n;
var escaped_content = content.replace(/"/g, '&#39;');
el.innerHTML = `<sup><span id="${key}" data-hover="${escaped_content}" style="cursor:pointer">${n}</span></sup>`;
});
let fnList = dom.querySelector("dt-fn-list");
let fnList = dom.querySelector('dt-fn-list');
if (fnList) {
let ol = dom.createElement("ol");
let ol = dom.createElement('ol');
fnContent.forEach(content => {
let el = dom.createElement("li");
let el = dom.createElement('li');
el.innerHTML = content;
ol.appendChild(el);
})
});
fnList.appendChild(ol);
}
+8 -8
View File
@@ -1,4 +1,4 @@
import ymlParse from "js-yaml";
import ymlParse from 'js-yaml';
export default function(dom, data) {
let localData = {};
@@ -8,27 +8,27 @@ export default function(dom, data) {
localData = ymlParse.safeLoad(text);
}
data.title = localData.title ? localData.title : "Untitled";
data.description = localData.description ? localData.description : "No description.";
data.title = localData.title ? localData.title : 'Untitled';
data.description = localData.description ? localData.description : 'No description.';
data.authors = localData.authors ? localData.authors : [];
data.authors = data.authors.map((author, i) =>{
let a = {};
let name = Object.keys(author)[0];
if ((typeof author) === "string") {
if ((typeof author) === 'string') {
name = author;
} else {
a.personalURL = author[name];
}
let names = name.split(" ");
let names = name.split(' ');
a.name = name;
a.firstName = names.slice(0, names.length - 1).join(" ");
a.firstName = names.slice(0, names.length - 1).join(' ');
a.lastName = names[names.length -1];
if(localData.affiliations[i]) {
let affiliation = Object.keys(localData.affiliations[i])[0];
if ((typeof localData.affiliations[i]) === "string") {
affiliation = localData.affiliations[i]
if ((typeof localData.affiliations[i]) === 'string') {
affiliation = localData.affiliations[i];
} else {
a.affiliationURL = localData.affiliations[i][affiliation];
}
+31 -31
View File
@@ -6,18 +6,18 @@ export default function(data) {
var date = data.publishedDate;
var batch_timestamp = Math.floor(Date.now() / 1000);
var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
batch_id += "_" + date.getFullYear();
batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : 'Anonymous';
batch_id += '_' + date.getFullYear();
batch_id += '_' + data.title.split(' ')[0].toLowerCase().slice(0,20) + '_' + batch_timestamp;
// generate XML
var crf_data =
{doi_batch : [
{ _attr: {
version: "4.3.7",
xmlns: "http://www.crossref.org/schema/4.3.7",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation": "http://www.crossref.org/schema/4.3.7 http://www.crossref.org/schemas/crossref4.3.7.xsd",
version: '4.3.7',
xmlns: 'http://www.crossref.org/schema/4.3.7',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation': 'http://www.crossref.org/schema/4.3.7 http://www.crossref.org/schemas/crossref4.3.7.xsd',
}},
{ head: [
@@ -62,8 +62,8 @@ export default function(data) {
data.authors.map((author, ind) => (
{person_name: [
{ _attr: {
contributor_role: "author",
sequence: (ind == 0)? "first" : "additional"
contributor_role: 'author',
sequence: (ind == 0)? 'first' : 'additional'
}},
{given_name: author.firstName},
{surname: author.lastName},
@@ -73,9 +73,9 @@ export default function(data) {
))
},
{publication_date: [
{month: date.getMonth()+1},
{day: date.getDate()},
{year: date.getFullYear()}
{month: date.getMonth()+1},
{day: date.getDate()},
{year: date.getFullYear()}
]},
{ publisher_item: [
{item_number: data.doi}
@@ -87,7 +87,7 @@ export default function(data) {
]},
{citation_list:
data.citations.map(key =>
citation_xml(key, data.bibliography[key]))
citation_xml(key, data.bibliography[key]))
}
]},
@@ -103,29 +103,29 @@ function citation_xml(key, ent){
if (ent == undefined) return {};
var info = [];
info.push({_attr: {key: key}});
if ("title" in ent)
if ('title' in ent)
info.push({article_title: ent.title});
if ("author" in ent)
info.push({author: ent.author.split(" and ")[0].split(",")[0].trim()});
if ("journal" in ent)
if ('author' in ent)
info.push({author: ent.author.split(' and ')[0].split(',')[0].trim()});
if ('journal' in ent)
info.push({journal_title: ent.journal});
if ("booktitle" in ent)
if ('booktitle' in ent)
info.push({volume_title: ent.booktitle});
if ("volume" in ent)
if ('volume' in ent)
info.push({volume: ent.volume});
if ("issue" in ent)
if ('issue' in ent)
info.push({issue: ent.issue});
if ("doi" in ent)
if ('doi' in ent)
info.push({doi: ent.doi});
return {citation: info}
return {citation: info};
}
function xml(obj) {
//console.log(typeof(obj), obj)
if (typeof obj === 'string') return obj;
if (typeof obj === 'number') return ""+obj;
if (typeof obj === 'number') return ''+obj;
let keys = Object.keys(obj);
if (keys.length != 1) console.error("can't interpret ", obj, "as xml");
if (keys.length != 1) console.error('can\'t interpret ', obj, 'as xml');
let name = keys[0];
var full_content = obj[name];
var attr = {};
@@ -134,8 +134,8 @@ function xml(obj) {
for (var i in full_content) {
var obj = full_content[i];
var obj_name = Object.keys(obj)[0];
if ("_attr" == obj_name) {
attr = obj["_attr"];
if ('_attr' == obj_name) {
attr = obj['_attr'];
} else {
//console.log(Object.keys(obj)[0])
content.push(obj);
@@ -145,19 +145,19 @@ function xml(obj) {
content = full_content;
}
if (content == undefined){
content = "undefined"
content = 'undefined';
}
let attr_string = "";
let attr_string = '';
for (var k in attr) {
attr_string += ` ${k}=\"${attr[k]}\"`
attr_string += ` ${k}=\"${attr[k]}\"`;
}
//console.log(typeof content, Array.isArray(content), content instanceof String, content)
if (Array.isArray(content)){
content = content.map(xml);
content = content.join("\n").split("\n");
content = content.map(s => " " + s).join("\n")
content = content.join('\n').split('\n');
content = content.map(s => ' ' + s).join('\n');
var result = `<${name}${attr_string}>\n${content}\n</${name}>`;
} else {
content = xml(content);
+5 -5
View File
@@ -1,4 +1,4 @@
import logo from "./distill-logo.svg";
import logo from './distill-logo.svg';
const html = `
<style>
@@ -77,16 +77,16 @@ dt-header .nav a {
<!-- https://twitter.com/distillpub -->
</div>
</div>
`
`;
export default function(dom, data) {
let el = dom.querySelector("dt-header");
let el = dom.querySelector('dt-header');
if(el) {
el.innerHTML = html;
} else {
let header = dom.createElement("dt-header");
let header = dom.createElement('dt-header');
header.innerHTML = html;
let b = dom.querySelector("body");
let b = dom.querySelector('body');
b.insertBefore(header, b.firstChild);
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
import code from './hover-box.txt';
export default function(dom) {
let s = dom.createElement("script");
let s = dom.createElement('script');
s.textContent = code;
dom.querySelector("body").appendChild(s);
dom.querySelector('body').appendChild(s);
}
+10 -10
View File
@@ -1,19 +1,19 @@
export default function(dom) {
if (!dom.querySelector("html").getAttribute("lang")) {
dom.querySelector("html").setAttribute("lang", "en")
if (!dom.querySelector('html').getAttribute('lang')) {
dom.querySelector('html').setAttribute('lang', 'en');
}
let head = dom.querySelector("head");
let head = dom.querySelector('head');
if (!dom.querySelector("meta[charset]")) {
let meta = dom.createElement("meta");
meta.setAttribute("charset", "utf-8");
if (!dom.querySelector('meta[charset]')) {
let meta = dom.createElement('meta');
meta.setAttribute('charset', 'utf-8');
head.appendChild(meta);
}
if (!dom.querySelector("meta[name=viewport]")) {
let meta = dom.createElement("meta");
meta.setAttribute("name", "viewport");
meta.setAttribute("content", "width=device-width, initial-scale=1");
if (!dom.querySelector('meta[name=viewport]')) {
let meta = dom.createElement('meta');
meta.setAttribute('name', 'viewport');
meta.setAttribute('content', 'width=device-width, initial-scale=1');
head.appendChild(meta);
}
}
+5 -5
View File
@@ -1,16 +1,16 @@
import fetch from "fetch";
let fetchUrl = fetch.fetchUrl
import fetch from 'fetch';
let fetchUrl = fetch.fetchUrl;
export default function(dom, data) {
var includeTags = [].slice.apply(dom.querySelectorAll("dt-include"));
var includeTags = [].slice.apply(dom.querySelectorAll('dt-include'));
includeTags.forEach(el => {
let src = el.getAttribute("src");
let src = el.getAttribute('src');
fetchUrl(src, (err, meta, body) => {
console.log(err, meta, body);
el.innerHTML = body.toString();
})
});
});
data.bibliography = bibliography;
data.citations = citations;
+2 -2
View File
@@ -10,9 +10,9 @@ export default function(dom, data) {
markdownElements.forEach(el => {
let content = el.innerHTML;
// Set default indents
content = content.replace(/\n/, "");
content = content.replace(/\n/, '');
let tabs = content.match(/\s*/);
content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
content = content.replace(new RegExp('\n' + tabs, 'g'), '\n');
content = content.trim();
el.innerHTML = marked(content);
+25 -25
View File
@@ -1,7 +1,7 @@
import favicon from './distill-favicon.base64';
export default function(dom, data) {
let head = dom.querySelector("head");
let head = dom.querySelector('head');
let appendHead = html => appendHtml(head, html);
function meta(name, content) {
@@ -24,7 +24,7 @@ export default function(dom, data) {
`);
data.authors.forEach((a) => {
appendHtml(head, `
<meta property="article:author" content="${a.firstName} ${a.lastName}" />`)
<meta property="article:author" content="${a.firstName} ${a.lastName}" />`);
});
appendHead(`
@@ -54,37 +54,37 @@ export default function(dom, data) {
appendHead(`
<!-- https://scholar.google.com/intl/en/scholar/inclusion.html#indexing -->\n`);
meta("citation_title", data.title);
meta("citation_fulltext_html_url", data.url);
meta("citation_volume", data.volume);
meta("citation_issue", data.issue);
meta("citation_firstpage", data.doiSuffix? `e${data.doiSuffix}` : undefined);
meta("citation_doi", data.doi);
meta('citation_title', data.title);
meta('citation_fulltext_html_url', data.url);
meta('citation_volume', data.volume);
meta('citation_issue', data.issue);
meta('citation_firstpage', data.doiSuffix? `e${data.doiSuffix}` : undefined);
meta('citation_doi', data.doi);
let journal = data.journal || {};
meta("citation_journal_title", journal.name);
meta("citation_journal_abbrev", journal.nameAbbrev);
meta("citation_issn", journal.issn);
meta("citation_publisher", journal.publisher);
meta('citation_journal_title', journal.name);
meta('citation_journal_abbrev', journal.nameAbbrev);
meta('citation_issn', journal.issn);
meta('citation_publisher', journal.publisher);
if (data.publishedDate){
let zeroPad = (n) => { return n < 10 ? "0" + n : n; };
meta("citation_publication_date", `${data.publishedYear}/${data.publishedMonthPadded}/${data.publishedDayPadded}`);
let zeroPad = (n) => { return n < 10 ? '0' + n : n; };
meta('citation_publication_date', `${data.publishedYear}/${data.publishedMonthPadded}/${data.publishedDayPadded}`);
}
(data.authors || []).forEach((a) => {
meta("citation_author", `${a.lastName}, ${a.firstName}`);
meta("citation_author_institution", a.affiliation);
meta('citation_author', `${a.lastName}, ${a.firstName}`);
meta('citation_author_institution', a.affiliation);
});
if (data.citations) {
data.citations.forEach(key => {
let d = data.bibliography[key];
if(!d) {
console.warn("No bibliography data fround for " + key)
console.warn('No bibliography data fround for ' + key);
} else {
meta("citation_reference", citation_meta_content(data.bibliography[key]) )
};
meta('citation_reference', citation_meta_content(data.bibliography[key]) );
}
});
}
}
@@ -96,17 +96,17 @@ function appendHtml(el, html) {
function citation_meta_content(ref){
var content = `citation_title=${ref.title};`;
ref.author.split(" and ").forEach(author => {
ref.author.split(' and ').forEach(author => {
content += `citation_author=${author.trim()};`;
});
if ("journal" in ref){
if ('journal' in ref){
content += `citation_journal_title=${ref.journal};`;
}
if ("volume" in ref) {
content += `citation_volume=${ref.volume};`;
if ('volume' in ref) {
content += `citation_volume=${ref.volume};`;
}
if ("issue" in ref || "number" in ref){
content += `citation_number=${ref.issue || ref.number};`;
if ('issue' in ref || 'number' in ref){
content += `citation_number=${ref.issue || ref.number};`;
}
/*content += `citation_first_page=${};`;
content += `citation_publication_date=${};`;*/
+2 -2
View File
@@ -5,7 +5,7 @@ import code from './styles-code.css';
import print from './styles-print.css';
export default function(dom) {
let s = dom.createElement("style");
let s = dom.createElement('style');
s.textContent = base + layout + article + code + print;
dom.querySelector("head").appendChild(s);
dom.querySelector('head').appendChild(s);
}
+21 -21
View File
@@ -6,7 +6,7 @@ export default function(dom, data) {
);
while (textNodes.nextNode()) {
var n = textNodes.currentNode,
text = n.nodeValue;
text = n.nodeValue;
if (text && acceptNode(n)) {
text = quotes(text);
text = punctuation(text);
@@ -17,19 +17,19 @@ export default function(dom, data) {
function acceptNode(node) {
var parent = node.parentElement;
var isMath = (parent && parent.getAttribute && parent.getAttribute("class")) ? parent.getAttribute("class").includes("katex") || parent.getAttribute("class").includes("MathJax") : false;
var isMath = (parent && parent.getAttribute && parent.getAttribute('class')) ? parent.getAttribute('class').includes('katex') || parent.getAttribute('class').includes('MathJax') : false;
return parent &&
parent.nodeName !== "SCRIPT" &&
parent.nodeName !== "STYLE" &&
parent.nodeName !== "CODE" &&
parent.nodeName !== "PRE" &&
parent.nodeName !== "SPAN" &&
parent.nodeName !== "D-HEADER" &&
parent.nodeName !== "D-BYLINE" &&
parent.nodeName !== "D-MATH" &&
parent.nodeName !== "D-CODE" &&
parent.nodeName !== "D-BIBLIOGRAPHY" &&
parent.nodeName !== "D-FOOTER" &&
parent.nodeName !== 'SCRIPT' &&
parent.nodeName !== 'STYLE' &&
parent.nodeName !== 'CODE' &&
parent.nodeName !== 'PRE' &&
parent.nodeName !== 'SPAN' &&
parent.nodeName !== 'D-HEADER' &&
parent.nodeName !== 'D-BYLINE' &&
parent.nodeName !== 'D-MATH' &&
parent.nodeName !== 'D-CODE' &&
parent.nodeName !== 'D-BIBLIOGRAPHY' &&
parent.nodeName !== 'D-FOOTER' &&
parent.nodeType !== 8 && //comment nodes
!isMath;
}
@@ -41,21 +41,21 @@ function acceptNode(node) {
* @link https://github.com/davidmerfield/Typeset.js
* @author David Merfield
*/
// which has a CC0 license
// http://creativecommons.org/publicdomain/zero/1.0/
// which has a CC0 license
// http://creativecommons.org/publicdomain/zero/1.0/
function punctuation(text){
// Dashes
text = text.replace(/--/g, '\u2014');
text = text.replace(/ \u2014 /g,"\u2009\u2014\u2009"); //this has thin spaces
text = text.replace(/ \u2014 /g,'\u2009\u2014\u2009'); //this has thin spaces
// Elipses
text = text.replace(/\.\.\./g,'…');
// Nbsp for punc with spaces
var NBSP = "\u00a0";
var NBSP = '\u00a0';
var NBSP_PUNCTUATION_START = /([«¿¡]) /g;
var NBSP_PUNCTUATION_END = / ([\!\?:;\.,‽»])/g;
@@ -91,8 +91,8 @@ function quotes(text) {
function ligatures(text){
text = text.replace(/fi/g, 'fi');
text = text.replace(/fl/g, 'fl');
text = text.replace(/fi/g, 'fi');
text = text.replace(/fl/g, 'fl');
return text;
};
return text;
}