-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 29974-nft-width
- Loading branch information
Showing
18 changed files
with
274 additions
and
33 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
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
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 |
---|---|---|
@@ -1,3 +1,30 @@ | ||
const NFT_ALT_TEXT_MAX_LENGTH = 100; | ||
|
||
export const nftTruncateAltText = (text, maxLength) => { | ||
// if the text is shorter than or equal to maxLength, return it | ||
if (text.length <= maxLength) { | ||
return text; | ||
} | ||
|
||
const truncated = text.substring(0, maxLength); | ||
const lastSpaceIndex = truncated.lastIndexOf(' '); | ||
|
||
// If there's a space within the truncated text, cut at the last space | ||
if (lastSpaceIndex > 0) { | ||
return `${truncated.substring(0, lastSpaceIndex)}...`; | ||
} | ||
|
||
// If no space is found, return the truncated text with ellipsis | ||
return `${truncated}...`; | ||
}; | ||
|
||
export const getNftImageAlt = ({ name, tokenId, description }) => { | ||
return description ?? `${name} ${tokenId}`; | ||
// If there is no name, tokenId, or description, return an empty string | ||
if (!name && !tokenId && !description) { | ||
return ''; | ||
} | ||
|
||
// if name or tokenId is undefined, don't include them in the alt text | ||
const altText = description ?? `${name ?? ''} ${tokenId ?? ''}`.trim(); | ||
return nftTruncateAltText(altText, NFT_ALT_TEXT_MAX_LENGTH); | ||
}; |
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
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
Oops, something went wrong.