Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-nails-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"crossref-utils": patch
---

Support abstract part
26 changes: 23 additions & 3 deletions src/cli/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
loadProject,
parseMyst,
processProject,
resolveFrontmatterParts,
selectors,
} from 'myst-cli';
import type { ISession } from 'myst-cli';
Expand Down Expand Up @@ -85,7 +86,9 @@ export async function depositArticleFromSource(session: ISession, depositSource:
} else {
fileContents.forEach(({ mdast }) => {
if (abstractPart) return;
abstractPart = extractPart(mdast, 'abstract');
abstractPart = extractPart(mdast, 'abstract', {
frontmatterParts: resolveFrontmatterParts(session, projectFrontmatter),
});
});
}
fileContents.forEach(({ references }) => {
Expand All @@ -108,7 +111,9 @@ export async function depositArticleFromSource(session: ISession, depositSource:
? projectFrontmatter?.subtitle ?? undefined
: frontmatter?.subtitle;
frontmatter = { ...fileContent.frontmatter, title, subtitle };
abstractPart = extractPart(fileContent.mdast, 'abstract');
abstractPart = extractPart(fileContent.mdast, 'abstract', {
frontmatterParts: resolveFrontmatterParts(session, frontmatter),
});
fileContent.references.cite?.order.forEach((key) => {
const value = fileContent.references.cite?.data[key].doi;
if (value) dois[key] = value;
Expand All @@ -117,6 +122,7 @@ export async function depositArticleFromSource(session: ISession, depositSource:
}

let abstract: Element | undefined;
const description = (frontmatter?.description || projectFrontmatter?.description)?.trim();
if (abstractPart) {
transformXrefToLink(abstractPart);
transformCiteToText(abstractPart);
Expand All @@ -128,6 +134,20 @@ export async function depositArticleFromSource(session: ISession, depositSource:
{ name: 'jats:abstract' },
jats.map((e) => element2JatsUnist(e)),
) as Element;
} else if (description) {
// Use the project description as the fallback for the abstract
abstractPart = {
type: 'root',
children: [{ type: 'paragraph', children: [{ type: 'text', value: description }] }],
};
transformNewlineToSpace(abstractPart);
const serializer = new JatsSerializer(new VFile(), abstractPart as any);
const jats = serializer.render(true).elements();
abstract = u(
'element',
{ name: 'jats:abstract' },
jats.map((e) => element2JatsUnist(e)),
) as Element;
}
return { frontmatter: frontmatter ?? {}, dois, abstract, configFile };
}
Expand Down Expand Up @@ -612,7 +632,7 @@ export async function deposit(session: ISession, opts: DepositOptions) {
throw new Error('preprint deposit may only use a single article');
}
const { frontmatter, dois, abstract } = depositArticles[0];
body = preprintFromMyst(frontmatter, dois, abstract);
body = preprintFromMyst(session, frontmatter, dois, abstract);
}
const batch = new DoiBatch(
{ id: opts.id ?? uuid(), depositor: { name, email }, registrant },
Expand Down
27 changes: 27 additions & 0 deletions src/funding.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Award, ProjectFrontmatter } from 'myst-frontmatter';
import type { Fundref } from './types.js';
import type { ISession } from 'myst-cli-utils';
import { e, t } from './utils.js';

export function fundrefFromMyst(
session: ISession,
Expand Down Expand Up @@ -35,3 +36,29 @@ export function fundrefFromMyst(
return { sources, awardNumbers };
});
}

export function createFundingXml(funding?: Fundref[]) {
if (!funding || funding.length === 0) return null;
return e(
'fr:program',
{ name: 'fundref' },
funding.map((fundingItem) => {
if (!fundingItem.sources.length) {
throw new Error('Fundref entry must have at least one source');
}
return e('fr:assertion', { name: 'fundgroup' }, [
...fundingItem.sources.map((source) => {
return e('fr:assertion', { name: 'funder_name' }, [
t(source.name),
...source.identifiers.map((id) => {
return e('fr:assertion', { name: 'funder_identifier' }, id);
}),
]);
}),
...fundingItem.awardNumbers.map((awardNumber) => {
return e('fr:assertion', { name: 'award_number' }, awardNumber);
}),
]);
}),
);
}
33 changes: 5 additions & 28 deletions src/journal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Element } from 'xast';
import { e, t } from './utils.js';
import { e } from './utils.js';
import type { JournalArticle, JournalIssue, JournalMetadata } from './types.js';
import { publicationDateXml } from './dates.js';
import type { ProjectFrontmatter } from 'myst-frontmatter';
import { contributorsXmlFromMystAuthors } from './contributors.js';
import { normalize } from 'doi-utils';
import { fundrefFromMyst } from './funding.js';
import { createFundingXml, fundrefFromMyst } from './funding.js';
import type { ISession } from 'myst-cli-utils';

/**
Expand Down Expand Up @@ -172,32 +172,9 @@ export function journalArticleXml({
children.push(e('pages', pageChildren));
}
// publisher_item
if (funding?.length) {
children.push(
e(
'fr:program',
{ name: 'fundref' },
funding.map((fundingItem) => {
if (!fundingItem.sources.length) {
throw new Error('Fundref entry must have at least one source');
}
return e('fr:assertion', { name: 'fundgroup' }, [
...fundingItem.sources.map((source) => {
return e('fr:assertion', { name: 'funder_name' }, [
t(source.name),
...source.identifiers.map((id) => {
return e('fr:assertion', { name: 'funder_identifier' }, id);
}),
]);
}),
...fundingItem.awardNumbers.map((awardNumber) => {
return e('fr:assertion', { name: 'award_number' }, awardNumber);
}),
]);
}),
),
);
}
const fundingXml = createFundingXml(funding);
if (fundingXml) children.push(fundingXml);

if (license) {
children.push(
e('ai:program', { name: 'AccessIndicators' }, [
Expand Down
9 changes: 9 additions & 0 deletions src/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { ProjectFrontmatter } from 'myst-frontmatter';
import { normalize } from 'doi-utils';
import { contributorsXmlFromMystAuthors } from './contributors.js';
import { dateXml } from './dates.js';
import { createFundingXml, fundrefFromMyst } from './funding.js';
import type { ISession } from 'myst-cli';

/**
* Create posted content xml
Expand All @@ -19,6 +21,7 @@ export function preprintXml({
title,
subtitle,
abstract,
funding,
doi_data,
citations,
license,
Expand All @@ -35,6 +38,10 @@ export function preprintXml({
children.push(e('titles', titles));
children.push(posted_date);
if (abstract) children.push(abstract);

const fundingXml = createFundingXml(funding);
if (fundingXml) children.push(fundingXml);

if (license) {
children.push(
e('ai:program', { name: 'AccessIndicators' }, [
Expand Down Expand Up @@ -85,6 +92,7 @@ export function preprintXml({
}

export function preprintFromMyst(
session: ISession,
myst: ProjectFrontmatter,
citations?: Record<string, string>,
abstract?: Element,
Expand All @@ -98,6 +106,7 @@ export function preprintFromMyst(
date: typeof date === 'string' ? new Date(date) : undefined,
license: license?.content?.url,
abstract,
funding: fundrefFromMyst(session, myst),
};
if (license && license.content?.CC) {
// Only put in CC licenses at this time
Expand Down