1 | import favicon from './distill-favicon.base64';
|
2 |
|
3 | export default function(dom, data) {
|
4 | let head = dom.querySelector("head");
|
5 | let appendHead = html => appendHtml(head, html);
|
6 |
|
7 | function meta(name, content) {
|
8 | if (content)
|
9 | appendHead(` <meta name="${name}" content="${content}" >\n`);
|
10 | }
|
11 |
|
12 | appendHead(`
|
13 | <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
|
14 | <link rel="icon" type="image/png" href="data:image/png;base64,${favicon}">
|
15 | <link href="/rss.xml" rel="alternate" type="application/rss+xml" title="Articles from Distill">
|
16 | <link rel="canonical" href="${data.url}">
|
17 | <title>${data.title}</title>
|
18 | `);
|
19 |
|
20 | appendHead(`
|
21 | <!-- https://schema.org/Article -->
|
22 | <meta property="article:published" itemprop="datePublished" content="${data.publishedYear}-${data.publishedMonthPadded}-${data.publishedDayPadded}" />
|
23 | `);
|
24 | data.authors.forEach((a) => {
|
25 | appendHtml(head, `
|
26 | <meta property="article:author" content="${a.firstName} ${a.lastName}" />`)
|
27 | });
|
28 |
|
29 | appendHead(`
|
30 | <!-- https://developers.facebook.com/docs/sharing/webmasters#markup -->
|
31 | <meta property="og:type" content="article"/>
|
32 | <meta property="og:title" content="${data.title}"/>
|
33 | <meta property="og:description" content="${data.description}">
|
34 | <meta property="og:url" content="${data.url}"/>
|
35 | <meta property="og:image" content="${data.url}/thumbnail.jpg"/>
|
36 | <meta property="og:locale" content="en_US" />
|
37 | <meta property="og:site_name" content="Distill" />
|
38 | `);
|
39 |
|
40 | appendHead(`
|
41 | <!-- https://dev.twitter.com/cards/types/summary -->
|
42 | <meta name="twitter:card" content="summary_large_image">
|
43 | <meta name="twitter:title" content="${data.title}">
|
44 | <meta name="twitter:description" content="${data.description}">
|
45 | <meta name="twitter:url" content="${data.url}">
|
46 | <meta name="twitter:image" content="${data.url}/thumbnail.jpg">
|
47 | <meta name="twitter:image:width" content="560">
|
48 | <meta name="twitter:image:height" content="295">
|
49 | `);
|
50 |
|
51 |
|
52 | if (data.doiSuffix){
|
53 | appendHead(`
|
54 | <!-- https://scholar.google.com/intl/en/scholar/inclusion.html#indexing -->\n`);
|
55 |
|
56 | meta("citation_title", data.title);
|
57 | meta("citation_fulltext_html_url", data.url);
|
58 | meta("citation_volume", data.volume);
|
59 | meta("citation_issue", data.issue);
|
60 | meta("citation_firstpage", data.doiSuffix? `e${data.doiSuffix}` : undefined);
|
61 | meta("citation_doi", data.doi);
|
62 |
|
63 | let journal = data.journal || {};
|
64 | meta("citation_journal_title", journal.name);
|
65 | meta("citation_journal_abbrev", journal.nameAbbrev);
|
66 | meta("citation_issn", journal.issn);
|
67 | meta("citation_publisher", journal.publisher);
|
68 |
|
69 | if (data.publishedDate){
|
70 | let zeroPad = (n) => { return n < 10 ? "0" + n : n; };
|
71 | meta("citation_publication_date", `${data.publishedYear}/${data.publishedMonthPadded}/${data.publishedDayPadded}`);
|
72 | }
|
73 |
|
74 | (data.authors || []).forEach((a) => {
|
75 | meta("citation_author", `${a.lastName}, ${a.firstName}`);
|
76 | meta("citation_author_institution", a.affiliation);
|
77 | });
|
78 |
|
79 | if (data.citations) {
|
80 | data.citations.forEach(key => {
|
81 | let d = data.bibliography[key];
|
82 | if(!d) {
|
83 | console.warn("No bibliography data fround for " + key)
|
84 | } else {
|
85 | meta("citation_reference", citation_meta_content(data.bibliography[key]) )
|
86 | };
|
87 | });
|
88 | }
|
89 | }
|
90 | }
|
91 |
|
92 | function appendHtml(el, html) {
|
93 | el.innerHTML += html;
|
94 | }
|
95 |
|
96 | function citation_meta_content(ref){
|
97 | var content = `citation_title=${ref.title};`;
|
98 | ref.author.split(" and ").forEach(author => {
|
99 | content += `citation_author=${author.trim()};`;
|
100 | });
|
101 | if ("journal" in ref){
|
102 | content += `citation_journal_title=${ref.journal};`;
|
103 | }
|
104 | if ("volume" in ref) {
|
105 | content += `citation_volume=${ref.volume};`;
|
106 | }
|
107 | if ("issue" in ref || "number" in ref){
|
108 | content += `citation_number=${ref.issue || ref.number};`;
|
109 | }
|
110 | |
111 |
|
112 | return content;
|
113 | }
|