mirror of
https://github.com/wassname/template.git
synced 2026-06-27 19:33:10 +08:00
234 lines
6.6 KiB
JavaScript
234 lines
6.6 KiB
JavaScript
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
|
const months = ['Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'];
|
|
const zeroPad = n => n < 10 ? '0' + n : n;
|
|
|
|
const RFC = function(date) {
|
|
const day = days[date.getDay()].substring(0, 3);
|
|
const paddedDate = zeroPad(date.getDate());
|
|
const month = months[date.getMonth()].substring(0,3);
|
|
const year = date.getFullYear().toString();
|
|
const hours = date.getUTCHours().toString();
|
|
const minutes = date.getUTCMinutes().toString();
|
|
const seconds = date.getUTCSeconds().toString();
|
|
return `${day}, ${paddedDate} ${month} ${year} ${hours}:${minutes}:${seconds} Z`;
|
|
};
|
|
|
|
class Author {
|
|
|
|
// constructor(name='', personalURL='', affiliation='', affiliationURL='') {
|
|
// this.name = name; // 'Chris Olah'
|
|
// this.personalURL = personalURL; // 'https://colah.github.io'
|
|
// this.affiliation = affiliation; // 'Google Brain'
|
|
// this.affiliationURL = affiliationURL; // 'https://g.co/brain'
|
|
// }
|
|
|
|
constructor(object) {
|
|
this.name = object.author; // 'Chris Olah'
|
|
this.personalURL = object.authorURL; // 'https://colah.github.io'
|
|
this.affiliation = object.affiliation; // 'Google Brain'
|
|
this.affiliationURL = object.affiliationURL; // 'https://g.co/brain'
|
|
}
|
|
|
|
// 'Chris'
|
|
get firstName() {
|
|
const names = this.name.split(' ');
|
|
return names.slice(0, names.length - 1).join(' ');
|
|
}
|
|
|
|
// 'Olah'
|
|
get lastName() {
|
|
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.authors = []; // Array of Author(s)
|
|
|
|
this.bibliography = new Map();
|
|
this.bibliographyParsed = false;
|
|
// {
|
|
// 'gregor2015draw': {
|
|
// 'title': 'DRAW: A recurrent neural network for image generation',
|
|
// 'author': 'Gregor, Karol and Danihelka, Ivo and Graves, Alex and Rezende, Danilo Jimenez and Wierstra, Daan',
|
|
// 'journal': 'arXiv preprint arXiv:1502.04623',
|
|
// 'year': '2015',
|
|
// 'url': 'https://arxiv.org/pdf/1502.04623.pdf',
|
|
// 'type': 'article'
|
|
// },
|
|
// }
|
|
|
|
// Citation keys should be listed in the order that they are appear in the document.
|
|
// Each key refers to a key in the bibliography dictionary.
|
|
this.citations = []; // [ 'gregor2015draw', 'mercier2011humans' ]
|
|
this.citationsCollected = false;
|
|
|
|
//
|
|
// Assigned from posts.csv
|
|
//
|
|
|
|
// publishedDate: 2016-09-08T07:00:00.000Z,
|
|
// tags: [ 'rnn' ],
|
|
// distillPath: '2016/augmented-rnns',
|
|
// githubPath: 'distillpub/post--augmented-rnns',
|
|
// doiSuffix: 1,
|
|
|
|
//
|
|
// Assigned from journal
|
|
//
|
|
this.journal = {};
|
|
// journal: {
|
|
// 'title': 'Distill',
|
|
// 'full_title': 'Distill',
|
|
// 'abbrev_title': 'Distill',
|
|
// 'url': 'http://distill.pub',
|
|
// 'doi': '10.23915/distill',
|
|
// 'publisherName': 'Distill Working Group',
|
|
// 'publisherEmail': 'admin@distill.pub',
|
|
// 'issn': '2476-0757',
|
|
// 'editors': [...],
|
|
// 'committee': [...]
|
|
// }
|
|
// volume: 1,
|
|
// issue: 9,
|
|
this.publishedDate = new Date();
|
|
|
|
this.katex = {};
|
|
|
|
//
|
|
// Assigned from publishing process
|
|
//
|
|
|
|
// githubCompareUpdatesUrl: 'https://github.com/distillpub/post--augmented-rnns/compare/1596e094d8943d2dc0ea445d92071129c6419c59...3bd9209e0c24d020f87cf6152dcecc6017cbc193',
|
|
// updatedDate: 2017-03-21T07:13:16.000Z,
|
|
// doi: '10.23915/distill.00001',
|
|
|
|
}
|
|
|
|
// Example:
|
|
// title: Demo Title Attention and Augmented Recurrent Neural Networks
|
|
// published: Jan 10, 2017
|
|
// authors:
|
|
// - Chris Olah:
|
|
// - Shan Carter: http://shancarter.com
|
|
// affiliations:
|
|
// - Google Brain:
|
|
// - Google Brain: http://g.co/brain
|
|
|
|
mergeFromYMLFrontmatter(data) {
|
|
this.title = data.title;
|
|
this.publishedDate = new Date(data.published);
|
|
this.description = data.description;
|
|
this.authors = data.authors.map( (authorObject) => new Author(authorObject));
|
|
this.katex = data.katex;
|
|
this.password = data.password;
|
|
}
|
|
|
|
//
|
|
// Computed Properties
|
|
//
|
|
|
|
// 'http://distill.pub/2016/augmented-rnns',
|
|
set url(value) {
|
|
this._url = value;
|
|
}
|
|
get url() {
|
|
if (this._url) {
|
|
return this._url;
|
|
} else if (this.distillPath && this.journal.url) {
|
|
return this.journal.url + '/' + this.distillPath;
|
|
} else if (this.journal.url) {
|
|
return this.journal.url;
|
|
}
|
|
}
|
|
|
|
// 'https://github.com/distillpub/post--augmented-rnns',
|
|
get githubUrl() {
|
|
return 'https://github.com/' + this.githubPath;
|
|
}
|
|
|
|
// TODO resolve differences in naming of URL/Url/url.
|
|
// 'http://distill.pub/2016/augmented-rnns/thumbnail.jpg',
|
|
set previewURL(value) {
|
|
this._previewURL = value;
|
|
}
|
|
get previewURL() {
|
|
return this._previewURL ? this._previewURL : this.url + '/thumbnail.jpg';
|
|
}
|
|
|
|
// 'Thu, 08 Sep 2016 00:00:00 -0700',
|
|
get publishedDateRFC() {
|
|
return RFC(this.publishedDate);
|
|
}
|
|
|
|
// 'Thu, 08 Sep 2016 00:00:00 -0700',
|
|
get updatedDateRFC() {
|
|
return RFC(this.updatedDate);
|
|
}
|
|
|
|
// 2016,
|
|
get publishedYear() {
|
|
return this.publishedDate.getFullYear();
|
|
}
|
|
|
|
// 'Sept',
|
|
get publishedMonth() {
|
|
return months[this.publishedDate.getMonth()];
|
|
}
|
|
|
|
// 8,
|
|
get publishedDay() {
|
|
return this.publishedDate.getDate();
|
|
}
|
|
|
|
// '09',
|
|
get publishedMonthPadded() {
|
|
return zeroPad(this.publishedDate.getMonth() + 1);
|
|
}
|
|
|
|
// '08',
|
|
get publishedDayPadded() {
|
|
return zeroPad(this.publishedDate.getDate());
|
|
}
|
|
|
|
// 'Olah & Carter',
|
|
get concatenatedAuthors() {
|
|
if (this.authors.length > 2) {
|
|
return this.authors[0].lastName + ', et al.';
|
|
} else if (this.authors.length === 2) {
|
|
return this.authors[0].lastName + ' & ' + this.authors[1].lastName;
|
|
} else if (this.authors.length === 1) {
|
|
return this.authors[0].lastName;
|
|
}
|
|
}
|
|
|
|
// 'Olah, Chris and Carter, Shan',
|
|
get bibtexAuthors() {
|
|
return this.authors.map(author => {
|
|
return author.lastName + ', ' + author.firstName;
|
|
}).join(' and ');
|
|
}
|
|
|
|
// 'olah2016attention'
|
|
get slug() {
|
|
let slug = '';
|
|
if (this.authors.length) {
|
|
slug += this.authors[0].lastName.toLowerCase();
|
|
slug += this.publishedYear;
|
|
slug += this.title.split(' ')[0].toLowerCase();
|
|
}
|
|
return slug || 'Untitled';
|
|
}
|
|
|
|
get bibliographyEntries() {
|
|
return new Map(this.citations.map( citationKey => {
|
|
const entry = this.bibliography.get(citationKey);
|
|
return [citationKey, entry];
|
|
}));
|
|
}
|
|
|
|
}
|