Project reorganization, add editorconfig and linter

This commit is contained in:
Ludwig Schubert
2017-08-04 10:28:30 -07:00
parent 07c7527734
commit 11eda0fc49
75 changed files with 1121 additions and 17118 deletions
+15
View File
@@ -0,0 +1,15 @@
root = true
[*]
indent_style = spaces
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{json,yml}]
indent_size = 2
[*.md]
trim_trailing_whitespace = false
+19
View File
@@ -0,0 +1,19 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": ["warn", { "vars": "all", "args": "after-used" }],
"no-console": ["off", { "allow": ["warn", "error"] } ],
"indent": [ "warn", 2 ],
"linebreak-style": [ "error", "unix" ],
"quotes": [ "warn", "single" ],
"semi": [ "warn", "always" ]
}
}
-72
View File
@@ -1,72 +0,0 @@
const templateHTML = `
<style>
dt-appendix {
display: block;
font-size: 14px;
line-height: 24px;
margin-bottom: 0;
border-top: 1px solid rgba(0,0,0,0.1);
color: rgba(0,0,0,0.5);
background: rgb(250, 250, 250);
padding-top: 36px;
padding-bottom: 60px;
}
dt-appendix h3 {
font-size: 16px;
font-weight: 500;
margin-top: 18px;
margin-bottom: 18px;
color: rgba(0,0,0,0.65);
}
dt-appendix .citation {
font-size: 11px;
line-height: 15px;
border-left: 1px solid rgba(0, 0, 0, 0.1);
padding-left: 18px;
border: 1px solid rgba(0,0,0,0.1);
background: rgba(0, 0, 0, 0.02);
padding: 10px 18px;
border-radius: 3px;
color: rgba(150, 150, 150, 1);
overflow: hidden;
margin-top: -12px;
}
dt-appendix .references {
font-size: 12px;
line-height: 20px;
}
dt-appendix a {
color: rgba(0, 0, 0, 0.6);
}
dt-appendix ol,
dt-appendix ul {
padding-left: 24px;
}
</style>
<div class="l-body">
</div>
`;
export default function(dom, data) {
let el = dom.querySelector('dt-appendix')
if (el) {
let userHTML = el.innerHTML;
el.innerHTML = templateHTML;
let newHTML = "";
// If we have some footnotes on the page, render a container for the footnote list.
if (dom.querySelector("dt-fn")) {
newHTML = newHTML + `<h3>Footnotes</h3><dt-fn-list></dt-fn-list>`;
}
// If we have any citations on the page, render a container for the bibliography.
if (dom.querySelector("dt-cite")) {
newHTML = newHTML + `<h3>References</h3><dt-bibliography></dt-bibliography>`;
}
let div = el.querySelector("div.l-body")
div.innerHTML = userHTML + newHTML;
}
}
-60
View File
@@ -1,60 +0,0 @@
class DataStore {
constructor() {
this.collections = new Map();
this.subscribers = new Map();
}
get(collectionName) {
return this.collections.get(collectionName);
}
set(collectionName, collection) {
this.collections.set(collectionName, collection);
// notify subscribers
if (this.subscribers.has(collectionName)) {
const subscribers = this.subscribers.get(collectionName);
for (const subscriber of subscribers) {
subscriber(collection);
}
}
}
register(collectionName, element) {
// create collection if it doesn't yet exist
if (!this.collections.has(collectionName)) {
this.collections.set(collectionName, []);
}
// add new element to collection
const collection = this.collections.get(collectionName);
collection.push(element);
// notify subscribers
if (this.subscribers.has(collectionName)) {
const subscribers = this.subscribers.get(collectionName);
for (const subscriber of subscribers) {
subscriber(element, collection);
}
}
}
subscribeTo(collectionName, callback) {
// create subscriber collection if it doesn't yet exist
if (!this.subscribers.has(collectionName)) {
this.subscribers.set(collectionName, []);
}
// add new callback to list of subscribers
const subscribers = this.subscribers.get(collectionName);
subscribers.push(callback);
// notify subscriber about existing collection entries
if (this.collections.has(collectionName)) {
const collection = this.collections.get(collectionName);
for (const entry of collection) {
callback(entry, collection);
}
}
}
}
// set up store
// export const Store = new DataStore();
+89 -16063
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
-81
View File
@@ -1,81 +0,0 @@
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};
-66
View File
@@ -1,66 +0,0 @@
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/expand-data";
import meta from "./components/meta";
import banner from "./components/banner";
import header from "./components/header";
import byline from "./components/byline";
import appendix from "./components/appendix";
import footer from "./components/footer";
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";
function renderImmediately(dom) {
html(dom);
styles(dom);
}
function renderOnLoad(dom, data) {
frontMatter(dom, data);
bibliography(dom, data);
expandData(dom, data);
meta(dom, data);
header(dom, data);
byline(dom, data);
appendix(dom, data);
footer(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...
if(window && window.document) {
let data = {};
renderImmediately(window.document);
window.document.addEventListener("DOMContentLoaded", (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);
});
}
// 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="http://distill.pub/template.js"]');
if (s) { s.parentElement.removeChild(s); };
}
export {render as render};
export {generateCrossref as generateCrossref};
+14
View File
@@ -0,0 +1,14 @@
{
"name": "distill-template",
"version": "2.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"eslint-config-google": {
"version": "0.9.1",
"resolved": "https://registry.npmjs.org/eslint-config-google/-/eslint-config-google-0.9.1.tgz",
"integrity": "sha512-5A83D+lH0PA81QMESKbLJd/a3ic8tPZtwUmqNrxMRo54nfFaUvtt89q/+icQ+fd66c2xQHn0KyFkzJDoAUfpZA==",
"dev": true
}
}
}
+11 -10
View File
@@ -1,6 +1,6 @@
{
"name": "distill-template",
"version": "0.0.21",
"version": "2.0.0",
"description": "Template for creating Distill articles.",
"main": "dist/template.js",
"author": "Shan Carter",
@@ -12,6 +12,7 @@
"start": "rollup -c rollup.config.components.js -w",
"serve": "python3 -m http.server --bind 127.0.0.1",
"test": "mocha",
"lint": "eslint",
"build": "rollup -c rollup.config.components.js"
},
"repository": {
@@ -21,29 +22,29 @@
"devDependencies": {
"bibtex-parse-js": "^0.0.23",
"chai": "^3.5.0",
"commander": "^2.9.0",
"eslint": "^4.3.0",
"eslint-config-google": "^0.9.1",
"js-yaml": "^3.7.0",
"jsdom": "^9.10.0",
"marked": "^0.3.6",
"mocha": "^3.2.0",
"prismjs": "^1.6.0",
"rollup": "latest",
"rollup-plugin-buble": "^0.14.0",
"rollup-plugin-babili": "^3.1.0",
"rollup-plugin-commonjs": "^7.0.0",
"rollup-plugin-copy": "^0.2.3",
"rollup-plugin-gzip": "^1.2.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-serve": "^0.1.0",
"rollup-plugin-string": "^2.0.2",
"rollup-plugin-uglify": "^1.0.1",
"rollup-watch": "^2.5.0"
"rollup-watch": "^2.5.0",
"webpack": "^2.2.1"
},
"dependencies": {
"@webcomponents/webcomponentsjs": "webcomponents/webcomponentsjs",
"commander": "^2.9.0",
"d3-time-format": "^2.0.3",
"katex": "^0.7.1",
"rollup-plugin-babili": "^3.1.0",
"rollup-plugin-copy": "^0.2.3",
"rollup-plugin-gzip": "^1.2.0",
"webcomponents.js": "webcomponents/webcomponentsjs",
"webpack": "^2.2.1"
"webcomponents.js": "webcomponents/webcomponentsjs"
}
}
+9 -15
View File
@@ -2,21 +2,20 @@ import copy from 'rollup-plugin-copy';
import resolve from 'rollup-plugin-node-resolve';
import string from 'rollup-plugin-string';
import commonjs from 'rollup-plugin-commonjs';
// import babili from 'rollup-plugin-babili';
// import gzip from 'rollup-plugin-gzip';
import serve from 'rollup-plugin-serve';
import babili from 'rollup-plugin-babili';
const PORT = 8080;
console.log(`opening http://localhost:${PORT} .../`);
export default {
entry: 'components.js',
entry: 'src/components.js',
sourceMap: true,
targets: [
{
format: 'iife',
moduleName: 'dl',
dest: `dist/components.js`,
dest: 'dist/components.js',
}
],
plugins: [
@@ -25,18 +24,13 @@ export default {
browser: true,
}),
string({
include: ["**/*.txt", "**/*.svg", "**/*.html", "**/*.css", "**/*.base64"]
include: ['**/*.txt', '**/*.svg', '**/*.html', '**/*.css', '**/*.base64']
}),
commonjs(),
// babili({
// comments: false, // means: *remove comments
// sourceMap: true,
// }),
// gzip(), // just for testing -- firebase CDN gzips automatically
// serve({
// port: PORT,
// open: true,
// })
babili({
comments: false, // means: *remove* comments
sourceMap: true,
}),
copy({
'node_modules/katex/dist/fonts': 'examples/fonts',
}),
-40
View File
@@ -1,40 +0,0 @@
import resolve from 'rollup-plugin-node-resolve';
import string from 'rollup-plugin-string';
import commonjs from 'rollup-plugin-commonjs';
import babili from 'rollup-plugin-babili';
import gzip from 'rollup-plugin-gzip';
import serve from 'rollup-plugin-serve';
const PORT = 8080;
console.log(`opening http://localhost:${PORT} .../`);
export default {
entry: 'template.v2.js',
sourceMap: true,
targets: [
{
format: 'umd',
moduleName: 'dl',
dest: `dist/template.v2.js`,
}
],
plugins: [
resolve({
jsnext: true,
browser: true,
}),
string({
include: ["**/*.txt", "**/*.svg", "**/*.html", "**/*.css", "**/*.base64"]
}),
commonjs(),
// babili({
// comments: false, // means: *remove* comments
// sourceMap: true,
// }),
// gzip(), // just for testing -- firebase CDN gzips automatically
serve({
port: PORT,
open: true,
})
]
};
+3 -3
View File
@@ -1,5 +1,5 @@
/* Static styles and other modules */
import * as Styles from './components/styles';
import './styles/styles';
/* Components */
import { Abstract } from './components/d-abstract';
@@ -25,8 +25,8 @@ const components = [
];
/* Distill website specific components */
import { DistillHeader } from "./distill-components/distill-header";
import { DistillAppendix } from "./distill-components/distill-appendix";
import { DistillHeader } from './distill-components/distill-header';
import { DistillAppendix } from './distill-components/distill-appendix';
const distillComponents = [
DistillHeader, DistillAppendix,
@@ -1,5 +1,5 @@
import { Template } from "../mixins/template";
import { body } from "./layout";
import { body } from "../helpers/layout";
const T = Template("d-abstract", `
<style>
@@ -1,5 +1,5 @@
import { Template } from "../mixins/template";
import { page } from "./layout";
import { page } from "../helpers/layout";
const T = Template("d-appendix", `
<style>
@@ -1,5 +1,5 @@
import { Template } from '../mixins/template';
import { Controller } from './controller';
import { Controller } from '../controller';
const T = Template('d-article', `
<style></style>
@@ -2,7 +2,7 @@ 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 "./citation";
import { bibliography_cite } from "../helpers/citation";
const T = Template('d-bibliography', `
<style>
@@ -1,5 +1,5 @@
import { Template } from "../mixins/template";
import { page } from "./layout";
import { page } from "../helpers/layout";
const T = Template("d-byline", `
<style>
@@ -1,6 +1,6 @@
import { Template } from "../mixins/template";
import { hover_cite } from "./citation";
import { HoverBox } from "./hover-box";
import { hover_cite } from "../helpers/citation";
import { HoverBox } from "../helpers/hover-box";
const T = Template('d-cite', `
<style>
@@ -1,5 +1,4 @@
import { Template } from "../mixins/template";
// import { Store } from './store';
import { Template } from '../mixins/template';
const T = Template('d-footnote-list', `
<style>
@@ -50,7 +49,7 @@ export class FootnoteList extends T(HTMLElement) {
this.list.innerHTML = '';
if (footnotes.length) {
// ensure footnote list is visible
this.root.host.style.display = 'initial'
this.root.host.style.display = 'initial';
for (const footnote of footnotes) {
// construct and append list item to show footnote
@@ -61,7 +60,7 @@ export class FootnoteList extends T(HTMLElement) {
const backlink = document.createElement('a');
backlink.setAttribute('class', 'footnote-backlink');
backlink.textContent = '[↩]';
backlink.href = `#${footnote.id}`;
backlink.href = '#' + footnote.id;
listItem.appendChild(backlink);
this.list.appendChild(listItem);
@@ -72,8 +71,4 @@ export class FootnoteList extends T(HTMLElement) {
}
}
renderFootnote(element) {
}
}
@@ -1,5 +1,5 @@
import { Template } from "../mixins/template.js"
import { HoverBox } from "./hover-box.js"
import { Template } from "../mixins/template.js";
import { HoverBox } from "../helpers/hover-box";
// import { Store } from './store';
const T = Template("d-footnote", `
@@ -1,7 +1,7 @@
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 katexCSS from "../../node_modules/katex/dist/katex.min.css"
const T = Template("d-math", `
<style>
@@ -1,5 +1,5 @@
import { Template } from "../mixins/template";
import { body } from "./layout";
import { body } from "../helpers/layout";
const T = Template("d-references", `
<style>
@@ -1,5 +1,5 @@
import { Template } from "../mixins/template";
import { page } from "./layout";
import { page } from "../helpers/layout";
const T = Template("d-title", `
<style>
+11 -23
View File
@@ -1,10 +1,8 @@
import { FrontMatter } from '../transforms/data';
import { collectCitations } from './d-cite';
import { FrontMatter } from './front-matter';
import { collectCitations } from './components/d-cite';
const frontMatter = new FrontMatter();
// set up global controller object
/* functions whose names start with 'on' will be registered as listeners on d-article */
export const Controller = {
frontMatter: frontMatter,
@@ -19,14 +17,14 @@ export const Controller = {
// ensure we have citations
if (frontMatter.citations.length === 0) {
console.debug('onCiteKeyCreated, but unresolved dependency ("citations"). Enqueing.');
// console.debug('onCiteKeyCreated, but unresolved dependency ("citations"). Enqueing.');
Controller.waitingOn.citations.push(() => Controller.listeners.onCiteKeyCreated(event));
return;
}
// ensure we have a loaded bibliography
if (frontMatter.bibliography.size === 0) {
console.debug('onCiteKeyCreated, but unresolved dependency ("bibliography"). Enqueing.');
// console.debug('onCiteKeyCreated, but unresolved dependency ("bibliography"). Enqueing.');
Controller.waitingOn.bibliography.push(() => Controller.listeners.onCiteKeyCreated(event));
return;
}
@@ -79,7 +77,7 @@ export const Controller = {
// ensure we have citations
if (frontMatter.citations.length === 0) {
console.debug('onBibliographyChanged, but unresolved dependency ("citations"). Enqueing.');
// console.debug('onBibliographyChanged, but unresolved dependency ("citations"). Enqueing.');
Controller.waitingOn.citations.push(() => Controller.listeners.onBibliographyChanged(event));
return;
}
@@ -90,8 +88,8 @@ export const Controller = {
bibliographyTag.entries = entries;
},
onFootnoteChanged(event) {
const footnote = event.detail;
onFootnoteChanged() {
// const footnote = event.detail;
//TODO: optimize to only update current footnote
const footnotesList = document.querySelector('d-footnote-list');
if (footnotesList) {
@@ -111,14 +109,14 @@ export const Controller = {
byline.frontMatter = frontMatter;
},
DOMContentLoaded(event) {
console.debug('DOMContentLoaded.');
DOMContentLoaded() {
// console.debug('DOMContentLoaded.');
const frontMatterTag = document.querySelector('d-front-matter');
const data = frontMatterTag.parse();
Controller.listeners.onFrontMatterChanged({detail: data});
console.debug('Resolving "citations" dependency due to initial DOM load.');
// console.debug('Resolving "citations" dependency due to initial DOM load.');
frontMatter.citations = collectCitations();
for (const waitingCallback of Controller.waitingOn.citations) {
waitingCallback();
@@ -129,18 +127,8 @@ export const Controller = {
const footnotes = document.querySelectorAll('d-footnote');
footnotesList.footnotes = footnotes;
}
}
}, // listeners
update: {
cite(element) {
},
footnoteList(element) {
}
}
} // Controller
}; // Controller
+1 -2
View File
@@ -97,6 +97,7 @@ export class FrontMatter {
// affiliations:
// - Google Brain:
// - Google Brain: http://g.co/brain
mergeFromYMLFrontmatter(data) {
this.title = data.title;
this.publishedDate = new Date(data.published);
@@ -131,8 +132,6 @@ export class FrontMatter {
return this.journal.url + "/" + this.distillPath;
} else if (this.journal.url) {
return this.journal.url;
} else {
return
}
}
@@ -2,7 +2,7 @@ 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 katex from '../../node_modules/katex/dist/katex.min.css'
let s = document.createElement("style");
s.textContent = base + layout + print + article + katex;
View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before

Width:  |  Height:  |  Size: 740 B

After

Width:  |  Height:  |  Size: 740 B

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 163 B

-49
View File
@@ -1,49 +0,0 @@
import {timeFormat} from "d3-time-format";
export default function(dom, data) {
data.authors = data.authors || [];
// paths
data.url = "http://distill.pub/" + data.distillPath;
data.githubUrl = "https://github.com/" + data.githubPath;
// Homepage
//data.homepage = !post.noHomepage;
data.journal = data.journal || {};
// Dates
if (data.publishedDate){//} && data.journal) {
data.volume = data.publishedDate.getFullYear() - 2015;
data.issue = data.publishedDate.getMonth() + 1;
}
data.publishedDate = data.publishedDate ? data.publishedDate : new Date("Invalid");
data.updatedDate = data.updatedDate ? data.updatedDate : new Date("Invalid");
let RFC = timeFormat("%a, %d %b %Y %H:%M:%S %Z");
let months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
let zeroPad = (n) => { return n < 10 ? "0" + n : n; };
data.publishedDateRFC = RFC(data.publishedDate);
data.publishedYear = data.publishedDate.getFullYear();
data.publishedMonth = months[data.publishedDate.getMonth()];
data.publishedDay = data.publishedDate.getDate();
data.publishedMonthPadded = zeroPad(data.publishedDate.getMonth() + 1);
data.publishedDayPadded = zeroPad(data.publishedDate.getDate());
data.updatedDateRFC = RFC(data.updatedDate);
if (data.authors.length > 2) {
data.concatenatedAuthors = data.authors[0].lastName + ", et al.";
} else if (data.authors.length === 2) {
data.concatenatedAuthors = data.authors[0].lastName + " & " + data.authors[1].lastName;
} else if (data.authors.length === 1) {
data.concatenatedAuthors = data.authors[0].lastName
}
data.bibtexAuthors = data.authors.map(function(author){
return author.lastName + ", " + author.firstName;
}).join(" and ");
data.slug = data.authors.length ? data.authors[0].lastName.toLowerCase() + data.publishedYear + data.title.split(" ")[0].toLowerCase() : "Untitled";
}
+932 -612
View File
File diff suppressed because it is too large Load Diff