Skip to content

Commit

Permalink
🎓 Only add author affiliations/contrib to template doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch committed Oct 13, 2023
1 parent 7f3d373 commit 43d221d
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-coins-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-templates': patch
---

Only add author affiliations/contrib to template doc
115 changes: 115 additions & 0 deletions packages/myst-templates/src/frontmatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]);
});
});
30 changes: 17 additions & 13 deletions packages/myst-templates/src/frontmatter.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion packages/myst-to-jats/src/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ function instWrapElementsFromAffiliation(affiliation: Affiliation, includeDept =
export function getArticleAffiliations(frontmatter: ProjectFrontmatter): Element[] {
if (!frontmatter.affiliations?.length) return [];
// Only add affiliations from authors, not contributors
const affIds = [...new Set(frontmatter.authors?.map((auth) => auth.affiliations ?? []).flat())];
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))
Expand Down

0 comments on commit 43d221d

Please sign in to comment.