-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
templates: fixes formatting issue with authors and footer not being a…
…t the bottom in the website template (#9969) Fixes: - formatting of authors when multiple, or missing or don't have names - footer not sticking to the bottom of the page
- Loading branch information
Showing
8 changed files
with
74 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 filteredAuthors = authors.filter((author) => Boolean(author.name)) | ||
|
||
if (filteredAuthors.length === 0) return '' | ||
if (filteredAuthors.length === 1) return filteredAuthors[0].name | ||
if (filteredAuthors.length === 2) | ||
return `${filteredAuthors[0].name} and ${filteredAuthors[1].name}` | ||
|
||
return `${filteredAuthors | ||
.slice(0, -1) | ||
.map((author) => author?.name) | ||
.join(', ')} and ${filteredAuthors[authors.length - 1].name}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
templates/with-vercel-website/src/utilities/formatAuthors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 filteredAuthors = authors.filter((author) => Boolean(author.name)) | ||
|
||
if (filteredAuthors.length === 0) return '' | ||
if (filteredAuthors.length === 1) return filteredAuthors[0].name | ||
if (filteredAuthors.length === 2) | ||
return `${filteredAuthors[0].name} and ${filteredAuthors[1].name}` | ||
|
||
return `${filteredAuthors | ||
.slice(0, -1) | ||
.map((author) => author?.name) | ||
.join(', ')} and ${filteredAuthors[authors.length - 1].name}` | ||
} |