diff --git a/.changeset/fluffy-dots-decide.md b/.changeset/fluffy-dots-decide.md new file mode 100644 index 000000000..29e8e1164 --- /dev/null +++ b/.changeset/fluffy-dots-decide.md @@ -0,0 +1,6 @@ +--- +'myst-cli-utils': patch +'myst-cli': patch +--- + +Improve plural function to add `y|ies` endings for words. diff --git a/packages/myst-cli-utils/src/utils.ts b/packages/myst-cli-utils/src/utils.ts index 5d4435453..2b98978d0 100644 --- a/packages/myst-cli-utils/src/utils.ts +++ b/packages/myst-cli-utils/src/utils.ts @@ -51,6 +51,8 @@ export function tic() { * * `plural('%s book(s)', books)` * + * `plural('%s dependenc(y|ies)', deps)` + * * If passed an object as the second argument, the number of keys will be used. */ export function plural(f: string, count?: number | any[] | Record): string { @@ -60,5 +62,8 @@ export function plural(f: string, count?: number | any[] | Record): st : Array.isArray(count) ? count?.length : Object.keys(count ?? {}).length) ?? 0; - return f.replace('%s', String(num)).replace(/\(s\)/g, num === 1 ? '' : 's'); + return f + .replace('%s', String(num)) + .replace(/\(s\)/g, num === 1 ? '' : 's') + .replace(/\(([a-z0-9A-Z-]*)\|([a-z0-9A-Z-]*)\)/g, num === 1 ? '$1' : '$2'); } diff --git a/packages/myst-cli/src/build/utils/getFileContent.ts b/packages/myst-cli/src/build/utils/getFileContent.ts index ab6c72c60..de6be5faf 100644 --- a/packages/myst-cli/src/build/utils/getFileContent.ts +++ b/packages/myst-cli/src/build/utils/getFileContent.ts @@ -1,5 +1,5 @@ import { resolve } from 'node:path'; -import { tic } from 'myst-cli-utils'; +import { plural, tic } from 'myst-cli-utils'; import type { LinkTransformer } from 'myst-transforms'; import type { ISession } from '../../session/types.js'; import { @@ -92,9 +92,10 @@ export async function getFileContent( ); session.log.info( toc( - `📚 Built ${allFiles.length} pages for export (including ${ - allFiles.length - files.length - } dependencies) from ${projectPath} in %s.`, + `📚 Built ${plural('%s page(s)', allFiles)} for export (including ${plural( + '%s dependenc(y|ies)', + allFiles.length - files.length, + )}) from ${projectPath} in %s.`, ), ); return selectedFiles;