From b24bf3deee5ca8f78fc0eb8fb17f8d4e8fa12b22 Mon Sep 17 00:00:00 2001 From: Marc Farra Date: Wed, 20 Mar 2024 15:28:12 +0000 Subject: [PATCH 1/3] use proper author format in citation --- .../scripts/components/documents/citation.js | 28 ++++++++----------- app/assets/scripts/utils/references.js | 2 +- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/assets/scripts/components/documents/citation.js b/app/assets/scripts/components/documents/citation.js index cfd7f3e5..3b72c074 100644 --- a/app/assets/scripts/components/documents/citation.js +++ b/app/assets/scripts/components/documents/citation.js @@ -5,6 +5,7 @@ import { FormHelperMessage } from '@devseed-ui/form'; import getDocumentIdKey from './get-document-id-key'; import { documentView } from '../../utils/url-creator'; +import { formatAuthors } from '../../utils/references'; // Symbol to define that the description should come from the strings file. export const formStringSymbol = Symbol.for('form string'); @@ -151,26 +152,21 @@ 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 publisher = atbd.citation.publisher; + const returnStr = `${authors}. (${year}). ${title}, ${getCitationDocVersion( + atbd + )}. ${publisher}. (${url})`; + return returnStr; } diff --git a/app/assets/scripts/utils/references.js b/app/assets/scripts/utils/references.js index 90a7f696..9ccf8c7b 100644 --- a/app/assets/scripts/utils/references.js +++ b/app/assets/scripts/utils/references.js @@ -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 '); From 075084d47c8c0f7b5030a49953b8b1b938ada45b Mon Sep 17 00:00:00 2001 From: Marc Farra Date: Thu, 21 Mar 2024 23:24:08 +0100 Subject: [PATCH 2/3] add DOI logic --- app/assets/scripts/components/documents/citation.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/scripts/components/documents/citation.js b/app/assets/scripts/components/documents/citation.js index 3b72c074..07138572 100644 --- a/app/assets/scripts/components/documents/citation.js +++ b/app/assets/scripts/components/documents/citation.js @@ -6,6 +6,8 @@ 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'); @@ -115,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) { @@ -164,9 +167,11 @@ export function createStringCitation(atbd) { const authors = formatAuthors(atbd.citation.creators, 'citation'); const title = atbd.title; const url = getCitationDocUrl(atbd); + const doi = atbd.doi; + let docRef = doi ? doi : url; const publisher = atbd.citation.publisher; const returnStr = `${authors}. (${year}). ${title}, ${getCitationDocVersion( atbd - )}. ${publisher}. (${url})`; + )}. ${publisher}. (${docRef})`; return returnStr; } From fd59d11e07061452e84da1371b88fa11db1f3bae Mon Sep 17 00:00:00 2001 From: Marc Farra Date: Tue, 26 Mar 2024 15:03:34 +0200 Subject: [PATCH 3/3] fix instructions --- app/assets/scripts/components/documents/citation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/scripts/components/documents/citation.js b/app/assets/scripts/components/documents/citation.js index 07138572..49fad389 100644 --- a/app/assets/scripts/components/documents/citation.js +++ b/app/assets/scripts/components/documents/citation.js @@ -19,8 +19,8 @@ export const citationFields = [ description: formStringSymbol, helper: ( - Separate values with and (e.g., John Doe and Jane - Doe). + Separate values with and (e.g. Doe, John and Doe, + Jane). ) }, @@ -30,8 +30,8 @@ export const citationFields = [ description: formStringSymbol, helper: ( - Separate values with and (e.g., John Doe and Jane - Doe). + Separate values with and (e.g. Doe, John and Doe, + Jane). ) },