import favicon from '../assets/distill-favicon.base64';
export default function(dom, data) {
let head = dom.querySelector('head');
let appendHead = html => appendHtml(head, html);
function meta(name, content) {
if (content)
appendHead(` \n`);
}
appendHead(`
${data.title}
`);
appendHead(`
`);
data.authors.forEach((a) => {
appendHtml(head, `
`);
});
appendHead(`
`);
appendHead(`
`);
// if this is a proprer article, generate Google Scholar meta data
if (data.doiSuffix){
appendHead(`
\n`);
meta('citation_title', data.title);
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);
let journal = data.journal || {};
meta('citation_journal_title', journal.name);
meta('citation_journal_abbrev', journal.nameAbbrev);
meta('citation_issn', journal.issn);
meta('citation_publisher', journal.publisher);
if (data.publishedDate){
meta('citation_publication_date', `${data.publishedYear}/${data.publishedMonthPadded}/${data.publishedDayPadded}`);
}
(data.authors || []).forEach((a) => {
meta('citation_author', `${a.lastName}, ${a.firstName}`);
meta('citation_author_institution', a.affiliation);
});
if (data.citations) {
data.citations.forEach(key => {
let d = data.bibliography[key];
if(!d) {
console.warn('No bibliography data fround for ' + key);
} else {
meta('citation_reference', citation_meta_content(data.bibliography[key]) );
}
});
}
}
}
function appendHtml(el, html) {
el.innerHTML += html;
}
function citation_meta_content(ref){
var content = `citation_title=${ref.title};`;
ref.author.split(' and ').forEach(author => {
content += `citation_author=${author.trim()};`;
});
if ('journal' in ref){
content += `citation_journal_title=${ref.journal};`;
}
if ('volume' in ref) {
content += `citation_volume=${ref.volume};`;
}
if ('issue' in ref || 'number' in ref){
content += `citation_number=${ref.issue || ref.number};`;
}
/*content += `citation_first_page=${};`;
content += `citation_publication_date=${};`;*/
return content;
}