mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 14:19:11 +03:00
* add cms turbo app * add cms scripts to package.json * update README * update README * update files * fix formatting * fix populateAuthors * sync dependencies * update launch week field * update lint config * Coordinate the deps to be the same as the other apps. * Remove extra files. * Run prettier on the CMS files. * Add commands for cleaning and typechecking. * Fix weird version of @types/react in docs. * run pnpm install * fix pnpm-lock * fix cms lint --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
25 lines
882 B
TypeScript
25 lines
882 B
TypeScript
import { Post } from '@/payload-types'
|
|
|
|
/**
|
|
* Formats an array of populatedAuthors from Posts into a prettified string.
|
|
* @param authors - The populatedAuthors array from a Post.
|
|
* @returns A prettified string of authors.
|
|
* @example
|
|
*
|
|
* [Author1, Author2] becomes 'Author1 and Author2'
|
|
* [Author1, Author2, Author3] becomes 'Author1, Author2, and Author3'
|
|
*
|
|
*/
|
|
export const formatAuthors = (
|
|
authors: NonNullable<NonNullable<Post['populatedAuthors']>[number]>[]
|
|
) => {
|
|
// Ensure we don't have any authors without a name
|
|
const authorNames = authors.map((author) => author.name).filter(Boolean)
|
|
|
|
if (authorNames.length === 0) return ''
|
|
if (authorNames.length === 1) return authorNames[0]
|
|
if (authorNames.length === 2) return `${authorNames[0]} and ${authorNames[1]}`
|
|
|
|
return `${authorNames.slice(0, -1).join(', ')} and ${authorNames[authorNames.length - 1]}`
|
|
}
|