Skip to content

Commit

Permalink
Merge pull request #581 from NASA-IMPACT/fix/825-citation-format
Browse files Browse the repository at this point in the history
Fix document info modal citation
  • Loading branch information
wrynearson authored Mar 26, 2024
2 parents 08c6a0b + fd59d11 commit a89ef35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
43 changes: 22 additions & 21 deletions app/assets/scripts/components/documents/citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { FormHelperMessage } from '@devseed-ui/form';

import getDocumentIdKey from './get-document-id-key';
import { documentView } from '../../utils/url-creator';
import { formatAuthors } from '../../utils/references';
import config from '../../config';
const { baseUrl } = config;

// Symbol to define that the description should come from the strings file.
export const formStringSymbol = Symbol.for('form string');
Expand All @@ -16,8 +19,8 @@ export const citationFields = [
description: formStringSymbol,
helper: (
<FormHelperMessage>
Separate values with <em>and</em> (e.g., John Doe <em>and</em> Jane
Doe).
Separate values with <em>and</em> (e.g. Doe, John <em>and</em> Doe,
Jane).
</FormHelperMessage>
)
},
Expand All @@ -27,8 +30,8 @@ export const citationFields = [
description: formStringSymbol,
helper: (
<FormHelperMessage>
Separate values with <em>and</em> (e.g., John Doe <em>and</em> Jane
Doe).
Separate values with <em>and</em> (e.g. Doe, John <em>and</em> Doe,
Jane).
</FormHelperMessage>
)
},
Expand Down Expand Up @@ -114,7 +117,8 @@ function getCitationDocUrl(atbd) {
return citation.online_resource;
}

return `${window.location.origin}${documentView(atbd)}`;
const publicUrl = baseUrl || window.location.origin;
return `${publicUrl}${documentView(atbd)}`;
}

function getCitationDocVersion(atbd) {
Expand Down Expand Up @@ -151,26 +155,23 @@ export function createBibtexCitation(atbd) {
}

/**
* Creates a comma separated citation from the given atbd.
* Creates a citation from the given atbd.
* Format is:
* Authors. (Publication Date). Title, version. Publisher. (DOC URL or DOI).
*
* @param {object} atbd The document for which to create a citation
* @returns string
*/
export function createStringCitation(atbd) {
const { title, citation } = atbd;
const { dateStr } = getCitationPublicationDate(atbd);
const citationVersion = getCitationDocVersion(atbd);
const { year } = getCitationPublicationDate(atbd);
const authors = formatAuthors(atbd.citation.creators, 'citation');
const title = atbd.title;
const url = getCitationDocUrl(atbd);

return [
title,
citation.creators,
citation.editors,
citation.publisher,
dateStr,
citationVersion,
url
]
.filter(Boolean)
.join(', ');
const doi = atbd.doi;
let docRef = doi ? doi : url;
const publisher = atbd.citation.publisher;
const returnStr = `${authors}. (${year}). ${title}, ${getCitationDocVersion(
atbd
)}. ${publisher}. (${docRef})`;
return returnStr;
}
2 changes: 1 addition & 1 deletion app/assets/scripts/utils/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const getReferenceEmptyValue = (base = {}) => {
* @param {String} authors - A list of authors separated by 'and'
* @returns A string of authors in AGU style
*/
function formatAuthors(authors, type = 'reference') {
export function formatAuthors(authors, type = 'reference') {
if (!authors || authors.length === 0) return '';
const authorsList = authors.split(' and ');

Expand Down

0 comments on commit a89ef35

Please sign in to comment.