import fullName from '../filters/full-name.js'
import formatUrl from '../filters/format-url.js'
import formatTitle from '../filters/format-title.js'
import initialLetter from '../filters/initial-letter.js'
import isDate from '../filters/is-date.js'
import lastNameFirst from '../filters/last-name-first.js'
import listCoauthors from './list-coauthors.js'
export default ({
author,
authors,
coauthors,
date,
location,
publication,
sponsor,
type,
title,
url
}) => {
var entry
var asAuthor = ''
var year = ''
title = formatTitle(title)
if(date && type !== 'research') {
year = isDate(date)
? `${date.getFullYear()}.`
: typeof date === 'string'
? `${date}.`
: 'n.d.'
}
if(author) {
asAuthor = lastNameFirst(author)
}
if(authors) {
asAuthor = authors.length < 4
? authors.map((author, index, arr) => listCoauthors(author, index, arr)).join(', ')
: `${authors} et al`
}
if(coauthors) {
asAuthor = coauthors.length > 1
? `<!--I’m one of multiple authors-->
Coauthored with ${coauthors.map((author, index, arr) => listCoauthors(author, index, arr)).join(', ')}`
: `<!--I’m one of two authors-->
Coauthored with ${fullName(coauthors[0])}`
}
asAuthor = asAuthor ? `${asAuthor}.` : ''
url = url ? `<a href="${url}" class="url">${formatUrl(url)}</a>.` : ''
if(type === 'journal') {
journal = ''
dateInfo = ''
volume = ''
issue = ''
pages = ''
if(publication) {
var {name: journal, volume, issue, pages, dateInfo} = publication
dateInfo = dateInfo
? ` (${dateInfo})`
: ` (${date.toLocaleDateString('en', {month: 'long'})})`
pages = pages ? `: ${pages}` : ''
var journalTitle = `<em>${journal}</em>`
var issueNumber = issue
? `${volume}, no. ${issue}`
: volume
var journalInfo = `${journalTitle} ${issueNumber}${dateInfo}${pages}`
}
title = `“${title}”`
journalInfo = sponsor ? sponsor : journalInfo
entry = `<!--${type}: see Turabian 2018, 19.2-->
${asAuthor} ${year} ${title} ${journalInfo}. ${url}`
}
if(type === 'magazine') {
var {name: magazine} = publication
date = date.toLocaleDateString('en', {month: 'long', day: 'numeric'})
magazine = `<em>${magazine}</em>,`
title = `“${title}”`
entry = `<!--${type}: see Turbian 2018, 19.3-->
${asAuthor} ${year} ${title} ${magazine} ${date}. ${url}`
}
if(type === 'website') {
var {page, owner} = publication
asAuthor ? asAuthor : owner
var website = asAuthor !== owner
? `${page}, ${owner}`
: owner
title = `“${title}”`
entry = `<!--${type}: see Turabian 2018, 19.5-->
${asAuthor} ${year} ${title} ${website}. ${url}`
}
if(type === 'lecture'
|| type === 'paper'
|| type === 'presentation'
|| type === 'sermon'
|| type === 'workshop'
|| type === 'master class') {
dateInfo = dateInfo
? `${dateInfo}`
: `${date.toLocaleDateString('en', {month: 'long', day: 'numeric'})}`
sponsor = sponsor ? `${sponsor},` : ''
title = `“${title}”`
var asType = type === 'paper'
? `${initialLetter(type)} presented at the`
: `${initialLetter(type)},`
var {name: place, city, state} = location
var eventInfo = `<!--eventInfo-->${place ? `${place},` : ''} ${city ? `${city}` : ''}${state ? `, ${state}` : ''}${dateInfo ? `, ${dateInfo}` : ''}`
entry = `<!--${type}: see Turabian 2018, 19.7.2-->
${asAuthor} ${year} ${title} ${asType} ${sponsor} ${eventInfo}. ${url}`
}
return entry
? `<!--_includes/shortcodes/author-date-reference.js-->
<article class="hanging-indent">
<p>${entry}</p>
</article>`
: `<!--no author-date format for type: ${type}-->`
}