mirror of
https://github.com/wassname/template.git
synced 2026-07-12 03:01:46 +08:00
refactor data object
This commit is contained in:
@@ -13,10 +13,11 @@ export default function(dom, data) {
|
||||
|
||||
// Dates
|
||||
// TODO: fix updated date
|
||||
if (data.published) {
|
||||
data.publishedDate = new Date(data.published);
|
||||
data.updatedDate = new Date(data.published || data.updated);
|
||||
|
||||
if (data.published){//} && data.journal) {
|
||||
data.volume = data.published.getFullYear() - 2015;
|
||||
data.issue = data.published.getMonth() + 1;
|
||||
}
|
||||
/*
|
||||
//let RFC = d3.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; };
|
||||
@@ -28,7 +29,7 @@ export default function(dom, data) {
|
||||
data.publishedDayPadded = zeroPad(data.publishedDate.getDate());
|
||||
data.volume = data.publishedDate.getFullYear() - 2015;
|
||||
data.issue = data.publishedDate.getMonth() + 1;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ export default function(dom, data) {
|
||||
|
||||
data.title = localData.title;
|
||||
data.description = localData.description;
|
||||
data.published = new Date(localData.published);
|
||||
data.updated = new Date(localData.published || localData.updated);
|
||||
|
||||
data.authors = localData.authors.map((author, i) =>{
|
||||
let a = {};
|
||||
let name = Object.keys(author)[0];
|
||||
@@ -24,6 +27,7 @@ export default function(dom, data) {
|
||||
}
|
||||
return a;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+36
-32
@@ -1,7 +1,13 @@
|
||||
export default function(dom, data) {
|
||||
let head = dom.querySelector("head");
|
||||
let appendHead = html => appendHtml(head, html);
|
||||
|
||||
appendHtml(head, `
|
||||
function meta(name, content) {
|
||||
if (content)
|
||||
appendHead(`<meta name="${name}" content="${content}" >`);
|
||||
}
|
||||
|
||||
appendHead(`
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
|
||||
<link rel="icon" type="image/png" href="/favicon.png">
|
||||
<link href="/rss.xml" rel="alternate" type="application/rss+xml" title="Articles from Distill">
|
||||
@@ -9,17 +15,17 @@ export default function(dom, data) {
|
||||
<title>${data.title}</title>
|
||||
`);
|
||||
|
||||
appendHtml(head, `
|
||||
appendHead(`
|
||||
<!-- https://schema.org/Article -->
|
||||
<meta property="article:published" itemprop="datePublished" content="${data.publishedDate}" />
|
||||
<meta property="article:modified" itemprop="dateModified" content="${data.updatedDate}" />
|
||||
<meta property="article:published" itemprop="datePublished" content="${data.published}" />
|
||||
<meta property="article:modified" itemprop="dateModified" content="${data.updated}" />
|
||||
`);
|
||||
data.authors.forEach((a) => {
|
||||
appendHtml(head, `
|
||||
<meta property="article:author" content="${a.firstName} ${a.lastName}" />`)
|
||||
});
|
||||
|
||||
appendHtml(head, `
|
||||
appendHead(`
|
||||
<!-- https://developers.facebook.com/docs/sharing/webmasters#markup -->
|
||||
<meta property="og:type" content="article"/>
|
||||
<meta property="og:title" content="${data.title}"/>
|
||||
@@ -30,7 +36,7 @@ export default function(dom, data) {
|
||||
<meta property="og:site_name" content="Distill" />
|
||||
`);
|
||||
|
||||
appendHtml(head, `
|
||||
appendHead(`
|
||||
<!-- https://dev.twitter.com/cards/types/summary -->
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:title" content="${data.title}">
|
||||
@@ -41,39 +47,37 @@ export default function(dom, data) {
|
||||
<meta name="twitter:image:height" content="295">
|
||||
`);
|
||||
|
||||
appendHtml(head, `
|
||||
appendHead(`
|
||||
<!-- https://scholar.google.com/intl/en/scholar/inclusion.html#indexing -->
|
||||
<meta name="citation_title" content="${data.title}">
|
||||
<meta name="citation_publication_date" content="${data.publishedYear}/${data.publishedMonthPadded}/${data.publishedDayPadded}">
|
||||
<meta name="citation_fulltext_html_url" content="${data.url}">
|
||||
<meta name="citation_volume" content="${data.volume}">
|
||||
<meta name="citation_issue" content="${data.issue}">
|
||||
<meta name="citation_firstpage" content="e${data.doiSuffix}"/>
|
||||
<meta name="citation_doi" content="${data.doi}">
|
||||
`);
|
||||
if (data.journal) {
|
||||
appendHtml(head, `
|
||||
<meta name="citation_journal_title" content="${data.journal.name}">
|
||||
<meta name="citation_journal_abbrev" content="${data.journal.nameAbbrev}"/>
|
||||
<meta name="citation_issn" content="${data.journal.issn}">
|
||||
<meta name="citation_publisher" content="${data.journal.publisher}"/>
|
||||
`);
|
||||
}
|
||||
|
||||
let journal = data.journal || {};
|
||||
let zeroPad = (n) => { return n < 10 ? "0" + n : n; };
|
||||
let publishedYear = data.published.getFullYear();
|
||||
let publishedMonthPadded = zeroPad(data.published.getMonth() + 1);
|
||||
let publishedDayPadded = zeroPad(data.published.getDate());
|
||||
meta("citation_title", data.title);
|
||||
meta("citation_publication_date", data.published? `${publishedYear}/${publishedMonthPadded}/${publishedDayPadded}` : undefined);
|
||||
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_journal_title", journal.name);
|
||||
meta("citation_journal_abbrev", journal.nameAbbrev);
|
||||
meta("citation_issn", journal.issn);
|
||||
meta("citation_publisher", journal.publisher);
|
||||
|
||||
(data.authors || []).forEach((a) => {
|
||||
appendHtml(head, `
|
||||
<meta name="citation_author" content="${a.lastName}, ${a.firstName}" />
|
||||
<meta name="citation_author_institution" content="${a.affiliation}"/>
|
||||
`)
|
||||
meta("citation_author", `${a.lastName}, ${a.firstName}`);
|
||||
meta("citation_author_institution", a.affiliation);
|
||||
});
|
||||
|
||||
if (data.citations) {
|
||||
let citationKeys = Object.keys(data.citations);
|
||||
citationKeys.forEach(key => {
|
||||
console.log(key);
|
||||
appendHtml(head, `
|
||||
<meta name="citation_reference" content="${citation_meta_content(data.citations[key])}" >
|
||||
`);
|
||||
});
|
||||
citationKeys.forEach(key =>
|
||||
meta("citation_reference", citation_meta_content(data.citations[key]) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<script type="text/front-matter">
|
||||
title: Article Title
|
||||
description: Description of the post
|
||||
published: Jan 10, 2017
|
||||
authors:
|
||||
- Chris Olah: http://colah.github.io
|
||||
- Shan Carter: http://shancarter.com
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
<dt-front-matter>
|
||||
title: Article Title
|
||||
description: Description of the post
|
||||
published: Jan 10, 2017
|
||||
authors:
|
||||
- Chris Olah: http://colah.github.io
|
||||
- Shan Carter: http://shancarter.com
|
||||
|
||||
@@ -14,6 +14,7 @@ import testData from "./test-data";
|
||||
|
||||
|
||||
function render(dom, data) {
|
||||
data = data || {};
|
||||
html(dom);
|
||||
styles(dom);
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
@@ -34,7 +35,7 @@ function render(dom, data) {
|
||||
|
||||
|
||||
if(window.document) {
|
||||
render(window.document, testData);
|
||||
render(window.document)//, testData);
|
||||
}
|
||||
|
||||
export default render;
|
||||
|
||||
Reference in New Issue
Block a user