Fix ordering of some tags; date formatting

This commit is contained in:
Ludwig Schubert
2017-10-23 15:47:05 -07:00
parent c742b36be6
commit d39819462a
10 changed files with 104 additions and 66 deletions
+1
View File
@@ -7,5 +7,6 @@ export default function(dom, data) {
return [citationKey, data.bibliography.get(citationKey)];
}));
renderCitationList(citationListTag, entries, dom);
citationListTag.setAttribute('distill-prerendered', 'true');
}
}
+20 -16
View File
@@ -1,3 +1,5 @@
// TODO: rewrite as template to make order dependencies easier
import favicon from '../assets/distill-favicon.base64';
import escape from 'escape-html';
@@ -16,37 +18,39 @@ export default function(dom, data) {
<link href="/rss.xml" rel="alternate" type="application/rss+xml" title="Articles from Distill">
`);
if (data.title) {
appendHead(`
<title>${escape(data.title)}</title>
`);
}
if (data.url) {
appendHead(`
<link rel="canonical" href="${data.url}">
`);
}
if (data.title) {
appendHead(`
<title>${data.title}</title>
`);
}
if (data.publishedDate){
appendHead(`
<!-- https://schema.org/Article -->
<meta property="article:published" itemprop="datePublished" content="${data.publishedYear}-${data.publishedMonthPadded}-${data.publishedDayPadded}" />
<meta property="article:created" itemprop="dateCreated" content="${data.publishedDate}" />
<meta property="article:modified" itemprop="dateModified" content="${data.updatedDate}" />
<meta property="description" itemprop="description" content="${escape(data.description)}" />
<meta property="article:published" itemprop="datePublished" content="${data.publishedISODateOnly}" />
<meta property="article:created" itemprop="dateCreated" content="${data.publishedISODateOnly}" />
<meta property="article:modified" itemprop="dateModified" content="${data.updatedDate.toISOString()}" />
`);
}
(data.authors || []).forEach((a) => {
appendHtml(head, `
<meta property="article:author" content="${a.firstName} ${a.lastName}" />`);
<meta property="article:author" content="${escape(a.firstName)} ${escape(a.lastName)}" />`);
});
appendHead(`
<!-- https://developers.facebook.com/docs/sharing/webmasters#markup -->
<meta property="og:type" content="article"/>
<meta property="og:title" content="${data.title}"/>
<meta property="og:description" content="${data.description}">
<meta property="og:title" content="${escape(data.title)}"/>
<meta property="og:description" content="${escape(data.description)}">
<meta property="og:url" content="${data.url}"/>
<meta property="og:image" content="${data.previewURL}"/>
<meta property="og:locale" content="en_US" />
@@ -56,8 +60,8 @@ export default function(dom, data) {
appendHead(`
<!-- https://dev.twitter.com/cards/types/summary -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="${data.title}">
<meta name="twitter:description" content="${data.description}">
<meta name="twitter:title" content="${escape(data.title)}">
<meta name="twitter:description" content="${escape(data.description)}">
<meta name="twitter:url" content="${data.url}">
<meta name="twitter:image" content="${data.previewURL}">
<meta name="twitter:image:width" content="560">
@@ -143,13 +147,13 @@ function citation_meta_content(ref){
return content; // arXiv is not considered a journal, so we don't need journal/volume/issue
}
if ('journal' in ref){
content += `citation_journal_title=${ref.journal};`;
content += `citation_journal_title=${escape(ref.journal)};`;
}
if ('volume' in ref) {
content += `citation_volume=${ref.volume};`;
content += `citation_volume=${escape(ref.volume)};`;
}
if ('issue' in ref || 'number' in ref){
content += `citation_number=${ref.issue || ref.number};`;
content += `citation_number=${escape(ref.issue || ref.number)};`;
}
return content;
}
+29 -35
View File
@@ -8,56 +8,50 @@
// if authors, no byline -> add byline
export default function(dom, data) {
const article = dom.querySelector('d-article');
const body = dom.body;
const article = body.querySelector('d-article');
// If we don't have an article tag, something weird is going on—giving up.
if (!article) {
console.warn('No d-article tag found; skipping adding optional components!');
return;
}
let byline = dom.querySelector('d-byline');
if (!byline) {
if (data.authors) {
byline = dom.createElement('d-byline');
body.insertBefore(byline, article);
} else {
console.warn('No authors found in front matter; please add them before submission!');
}
}
let title = dom.querySelector('d-title');
if (!title) {
let title = dom.createElement('d-title');
body.insertBefore(title, byline);
}
let h1 = title.querySelector('h1');
if (!h1) {
h1 = dom.createElement('h1');
h1.textContent = data.title;
title.insertBefore(h1, title.firstChild);
}
const hasPassword = typeof data.password !== 'undefined';
let interstitial = dom.querySelector('d-interstitial');
let interstitial = body.querySelector('d-interstitial');
if (hasPassword && !interstitial) {
const inBrowser = typeof window !== 'undefined';
const onLocalhost = inBrowser && window.location.hostname.includes('localhost');
if (!inBrowser || !onLocalhost) {
interstitial = dom.createElement('d-interstitial');
interstitial.password = data.password;
dom.body.insertBefore(interstitial, dom.body.firstChild);
body.insertBefore(interstitial, body.firstChild);
}
}
// let h1 = dom.querySelector('h1');
// if (h1) {
// if (!data.title) {
// data.title = h1.textContent;
// }
// } else {
// if (data.title) {
// let headline = dom.createElement('d-title');
// let h1 = dom.createElement('h1');
// headline.appendChild(h1);
// h1.textContent = data.title;
// abstract.parentNode.insertBefore(headline, abstract);
// }
// if (data.description) {
// const h2 = dom.createElement('h2');
// h2.textContent = data.description;
// article.insertBefore(h2, h1.nextSibling);
// }
// }
let byline = dom.querySelector('d-byline');
if (!byline && data.authors) {
byline = dom.createElement('d-byline');
article.parentNode.insertBefore(byline, article);
// const skipTags = ['H1', 'FIGURE', 'D-ABSTRACT'];
// let candidate = h1;
// while (skipTags.indexOf(candidate.tagName) !== -1) {
// candidate = candidate.nextSibling;
// }
// article.insertBefore(byline, candidate);
}
let appendix = dom.querySelector('d-appendix');
if (!appendix) {
appendix = dom.createElement('d-appendix');
+17
View File
@@ -0,0 +1,17 @@
/*
Try to only reorder things that MAY be user defined.
Try to use templates etc to define the order of our own tags.
*/
export default function render(dom) {
const head = dom.head;
const metaIE = head.querySelector('meta[http-equiv]');
head.insertBefore(metaIE, head.firstChild);
const metaViewport = head.querySelector('meta[name=viewport]');
head.insertBefore(metaViewport, head.firstChild);
const metaCharset = head.querySelector('meta[charset]');
head.insertBefore(metaCharset, head.firstChild);
}