diff --git a/.changeset/cyan-coins-guess.md b/.changeset/cyan-coins-guess.md new file mode 100644 index 000000000..9ce87a015 --- /dev/null +++ b/.changeset/cyan-coins-guess.md @@ -0,0 +1,5 @@ +--- +'myst-templates': patch +--- + +Only add author affiliations/contrib to template doc diff --git a/.changeset/light-shirts-tease.md b/.changeset/light-shirts-tease.md new file mode 100644 index 000000000..71d4c255d --- /dev/null +++ b/.changeset/light-shirts-tease.md @@ -0,0 +1,5 @@ +--- +'myst-to-jats': patch +--- + +JATS only includes authors as top-level contribs diff --git a/.changeset/metal-pans-remember.md b/.changeset/metal-pans-remember.md new file mode 100644 index 000000000..9fc23e0f4 --- /dev/null +++ b/.changeset/metal-pans-remember.md @@ -0,0 +1,5 @@ +--- +'myst-to-jats': patch +--- + +Remove contrib id, authors cannot be referenced. diff --git a/.changeset/purple-dancers-report.md b/.changeset/purple-dancers-report.md new file mode 100644 index 000000000..8506399da --- /dev/null +++ b/.changeset/purple-dancers-report.md @@ -0,0 +1,5 @@ +--- +'myst-to-jats': patch +--- + +JATS only includes author affiliations in aff list diff --git a/packages/myst-templates/src/frontmatter.spec.ts b/packages/myst-templates/src/frontmatter.spec.ts index 3ed9dfbd3..80dd9eb72 100644 --- a/packages/myst-templates/src/frontmatter.spec.ts +++ b/packages/myst-templates/src/frontmatter.spec.ts @@ -164,4 +164,119 @@ describe('extendFrontmatter', () => { }, ]); }); + it('affiliations are only used from authors', async () => { + const frontmatter: PageFrontmatter = { + authors: [ + { + name: 'John Doe', + affiliations: ['aff1'], + }, + { + name: 'Jane Doe', + affiliations: ['aff1', 'col2'], + }, + ], + affiliations: [ + { + id: 'aff1', + name: 'univ 1', + }, + { + id: 'aff2', + name: 'univ 2', + }, + { + id: 'col1', + name: 'group 1', + collaboration: true, + }, + { + id: 'col2', + name: 'group 2', + collaboration: true, + }, + ], + }; + const doc = extendFrontmatter(frontmatter); + expect(doc.authors).toEqual([ + { + name: 'John Doe', + given_name: 'John', + surname: 'Doe', + index: 1, + letter: 'A', + affiliations: [ + { + id: 'aff1', + name: 'univ 1', + value: { + id: 'aff1', + name: 'univ 1', + }, + index: 1, + letter: 'A', + }, + ], + }, + { + name: 'Jane Doe', + given_name: 'Jane', + surname: 'Doe', + index: 2, + letter: 'B', + affiliations: [ + { + id: 'aff1', + name: 'univ 1', + value: { + id: 'aff1', + name: 'univ 1', + }, + index: 1, + letter: 'A', + }, + ], + collaborations: [ + { + id: 'col2', + name: 'group 2', + collaboration: true, + value: { + id: 'col2', + name: 'group 2', + collaboration: true, + }, + index: 1, + letter: 'A', + }, + ], + }, + ]); + expect(doc.affiliations).toEqual([ + { + id: 'aff1', + name: 'univ 1', + value: { + id: 'aff1', + name: 'univ 1', + }, + index: 1, + letter: 'A', + }, + ]); + expect(doc.collaborations).toEqual([ + { + id: 'col2', + name: 'group 2', + collaboration: true, + value: { + id: 'col2', + name: 'group 2', + collaboration: true, + }, + index: 1, + letter: 'A', + }, + ]); + }); }); diff --git a/packages/myst-templates/src/frontmatter.ts b/packages/myst-templates/src/frontmatter.ts index fbb9b264d..0cb3eb29d 100644 --- a/packages/myst-templates/src/frontmatter.ts +++ b/packages/myst-templates/src/frontmatter.ts @@ -1,4 +1,4 @@ -import type { Contributor, PageFrontmatter } from 'myst-frontmatter'; +import type { Affiliation, Contributor, PageFrontmatter } from 'myst-frontmatter'; import type { RendererAuthor, RendererDoc, ValueAndIndex } from './types.js'; const ALPHA = 'ABCDEFGHIJKLMNOPQURSUVWXYZ'; @@ -71,18 +71,22 @@ function addIndicesToAuthors( export function extendFrontmatter(frontmatter: PageFrontmatter): RendererDoc { const datetime = frontmatter.date ? new Date(frontmatter.date) : new Date(); - const affiliations = - frontmatter.affiliations - ?.filter((aff) => aff.id && !aff.collaboration) - .map((aff, index) => { - return { ...aff, value: aff, ...indexAndLetter(index) }; - }) ?? []; - const collaborations = - frontmatter.affiliations - ?.filter((aff) => aff.id && aff.collaboration) - .map((aff, index) => { - return { ...aff, value: aff, ...indexAndLetter(index) }; - }) ?? []; + // Only add affiliations from authors, not contributors + const affIds = [ + ...new Set(frontmatter.authors?.map((auth) => auth.affiliations ?? []).flat() ?? []), + ]; + const affiliations = affIds + .map((id) => frontmatter.affiliations?.find((aff) => aff.id === id)) + .filter((aff): aff is Affiliation => !!aff?.id && !aff.collaboration) + .map((aff, index) => { + return { ...aff, value: aff, ...indexAndLetter(index) }; + }); + const collaborations = affIds + .map((id) => frontmatter.affiliations?.find((aff) => aff.id === id)) + .filter((aff): aff is Affiliation => !!aff?.id && !!aff.collaboration) + .map((aff, index) => { + return { ...aff, value: aff, ...indexAndLetter(index) }; + }); const doc: RendererDoc = { ...frontmatter, date: { diff --git a/packages/myst-to-jats/src/frontmatter.ts b/packages/myst-to-jats/src/frontmatter.ts index 9cf9730b9..805e215a9 100644 --- a/packages/myst-to-jats/src/frontmatter.ts +++ b/packages/myst-to-jats/src/frontmatter.ts @@ -160,7 +160,6 @@ export function getArticleAuthors(frontmatter: ProjectFrontmatter): Element[] { const attributes: Record = {}; const elements: Element[] = []; if (type) attributes['contrib-type'] = type; - if (author.id) attributes.id = author.id; if (author.corresponding) attributes.corresp = 'yes'; if (author.deceased) attributes['deceased'] = 'yes'; if (author.equal_contributor != null) { @@ -228,16 +227,10 @@ export function getArticleAuthors(frontmatter: ProjectFrontmatter): Element[] { const authorContribs = (frontmatter.authors ?? []).map((author): Element => { return generateContrib(author, 'author'); }); - const otherContribs = (frontmatter.contributors ?? []).map((contributor): Element => { - return generateContrib(contributor); - }); const contribGroups: Element[] = []; if (authorContribs.length) { contribGroups.push({ type: 'element', name: 'contrib-group', elements: authorContribs }); } - if (otherContribs.length) { - contribGroups.push({ type: 'element', name: 'contrib-group', elements: otherContribs }); - } return contribGroups; } @@ -309,84 +302,93 @@ function instWrapElementsFromAffiliation(affiliation: Affiliation, includeDept = } export function getArticleAffiliations(frontmatter: ProjectFrontmatter): Element[] { - const affs = frontmatter.affiliations?.map((affiliation): Element => { - const elements: Element[] = []; - const attributes: Record = {}; - if (affiliation.id) { - attributes.id = affiliation.id; - } - elements.push(...instWrapElementsFromAffiliation(affiliation)); - if (affiliation.address) { - elements.push({ - type: 'element', - name: 'addr-line', - elements: [{ type: 'text', text: affiliation.address }], - }); - } - if (affiliation.city) { - elements.push({ - type: 'element', - name: 'city', - elements: [{ type: 'text', text: affiliation.city }], - }); - } - if (affiliation.state) { - elements.push({ - type: 'element', - name: 'state', - elements: [{ type: 'text', text: affiliation.state }], - }); - } - if (affiliation.postal_code) { - elements.push({ - type: 'element', - name: 'postal-code', - elements: [{ type: 'text', text: affiliation.postal_code }], - }); - } - if (affiliation.country) { - elements.push({ - type: 'element', - name: 'country', - elements: [{ type: 'text', text: affiliation.country }], - }); - } - if (affiliation.phone) { - elements.push({ - type: 'element', - name: 'phone', - elements: [{ type: 'text', text: affiliation.phone }], - }); - } - if (affiliation.fax) { - elements.push({ - type: 'element', - name: 'fax', - elements: [{ type: 'text', text: affiliation.fax }], - }); - } - if (affiliation.email) { - elements.push({ - type: 'element', - name: 'email', - elements: [{ type: 'text', text: affiliation.email }], - }); - } - if (affiliation.url) { - elements.push({ + if (!frontmatter.affiliations?.length) return []; + // Only add affiliations from authors, not contributors + const affIds = [ + ...new Set(frontmatter.authors?.map((auth) => auth.affiliations ?? []).flat() ?? []), + ]; + if (!affIds?.length) return []; + const affs = affIds + .map((id) => frontmatter.affiliations?.find((aff) => aff.id === id)) + .filter((aff): aff is Affiliation => !!aff) + .map((affiliation): Element => { + const elements: Element[] = []; + const attributes: Record = {}; + if (affiliation.id) { + attributes.id = affiliation.id; + } + elements.push(...instWrapElementsFromAffiliation(affiliation)); + if (affiliation.address) { + elements.push({ + type: 'element', + name: 'addr-line', + elements: [{ type: 'text', text: affiliation.address }], + }); + } + if (affiliation.city) { + elements.push({ + type: 'element', + name: 'city', + elements: [{ type: 'text', text: affiliation.city }], + }); + } + if (affiliation.state) { + elements.push({ + type: 'element', + name: 'state', + elements: [{ type: 'text', text: affiliation.state }], + }); + } + if (affiliation.postal_code) { + elements.push({ + type: 'element', + name: 'postal-code', + elements: [{ type: 'text', text: affiliation.postal_code }], + }); + } + if (affiliation.country) { + elements.push({ + type: 'element', + name: 'country', + elements: [{ type: 'text', text: affiliation.country }], + }); + } + if (affiliation.phone) { + elements.push({ + type: 'element', + name: 'phone', + elements: [{ type: 'text', text: affiliation.phone }], + }); + } + if (affiliation.fax) { + elements.push({ + type: 'element', + name: 'fax', + elements: [{ type: 'text', text: affiliation.fax }], + }); + } + if (affiliation.email) { + elements.push({ + type: 'element', + name: 'email', + elements: [{ type: 'text', text: affiliation.email }], + }); + } + if (affiliation.url) { + elements.push({ + type: 'element', + name: 'ext-link', + attributes: { 'ext-link-type': 'uri', 'xlink:href': affiliation.url }, + elements: [{ type: 'text', text: affiliation.url }], + }); + } + return { type: 'element', - name: 'ext-link', - attributes: { 'ext-link-type': 'uri', 'xlink:href': affiliation.url }, - elements: [{ type: 'text', text: affiliation.url }], - }); - } - return { - type: 'element', - name: 'aff', - attributes, - elements, - }; - }); + name: 'aff', + attributes, + elements, + }; + }); return affs ? affs : []; } diff --git a/packages/myst-to-jats/tests/affiliations.yml b/packages/myst-to-jats/tests/affiliations.yml index 116fe8f1d..6efacbce0 100644 --- a/packages/myst-to-jats/tests/affiliations.yml +++ b/packages/myst-to-jats/tests/affiliations.yml @@ -8,6 +8,11 @@ cases: - type: text value: text frontmatter: + authors: + - name: John Doe + affiliations: + - univa + - univb affiliations: - id: univa name: University A @@ -32,6 +37,16 @@ cases:
+ + + + Doe + John + + + + + University A diff --git a/packages/myst-to-jats/tests/authors.yml b/packages/myst-to-jats/tests/authors.yml index 844e41b42..37d3c5565 100644 --- a/packages/myst-to-jats/tests/authors.yml +++ b/packages/myst-to-jats/tests/authors.yml @@ -44,7 +44,7 @@ cases: - + 0000-0000-0000-0000 Doe @@ -58,14 +58,14 @@ cases: example@example.com https://example.com - + Doe John Jr. - + John Doe III diff --git a/packages/myst-to-jats/tests/funding.yml b/packages/myst-to-jats/tests/funding.yml index 9d8a04958..964205b37 100644 --- a/packages/myst-to-jats/tests/funding.yml +++ b/packages/myst-to-jats/tests/funding.yml @@ -79,26 +79,13 @@ cases: - + Doe John - - - - Doe - Jane - - - - - - University A - - @@ -181,7 +168,7 @@ cases: - + 0000-0000-0000-0000 Doe @@ -190,19 +177,6 @@ cases: - - - - Doe - Jane - - - - - - University B - - University A @@ -211,11 +185,6 @@ cases: Some Department - - - University C - - @@ -327,7 +296,7 @@ cases: - + 0000-0000-0000-0000 Doe @@ -336,15 +305,6 @@ cases: - - - University B - 0000000000000001 - 99998 - 0000000000000001 - 10.1000/efg012 - - University A diff --git a/packages/myst-to-jats/tests/multi.yml b/packages/myst-to-jats/tests/multi.yml index 0cdaf03a2..d2b2e276d 100644 --- a/packages/myst-to-jats/tests/multi.yml +++ b/packages/myst-to-jats/tests/multi.yml @@ -167,21 +167,13 @@ cases: Top title - + One Author - - - - Two - Author - - - @@ -200,7 +192,7 @@ cases: - + Three Author