cal/packages/lib/text.ts
Jeroen Reumkens 5c01467caa
#4252 Use vercel og to generate og images for meetings and apps. (#4943)
* #4252 Use vercel og to generate og images for meetings and apps.

* Removed duplication.

* Added new design for og images (wip).

* Implemented og image design for meeting image, including support for all variants.

* Implemented design for app og images.

* clenaup

* Fixed types

* Added the option to not render headseo in main shell in order to render your own.

* Added comments.

* fix

* Small tweaks.

* Fixed lock file.

* Fixed types

* Optimized svg's so vercel og supports them.

* Fixed og image on user page.

* Added truncate utils.

* Small style tweaks

* App og image alignment.

* Added og image to team/slug pages.

* Added correct variable to og image path constant.
2022-10-18 11:46:22 -06:00

18 lines
695 B
TypeScript

export const truncate = (text: string, maxLength: number, ellipsis = true) => {
if (text.length <= maxLength) return text;
return `${text.slice(0, maxLength - 3)}${ellipsis ? "..." : ""}`;
};
export const truncateOnWord = (text: string, maxLength: number, ellipsis = true) => {
if (text.length <= maxLength) return text;
// First split on maxLength chars
let truncatedText = text.substring(0, 148);
// Then split on the last space, this way we split on the last word,
// which looks just a bit nicer.
truncatedText = truncatedText.substring(0, Math.min(truncatedText.length, truncatedText.lastIndexOf(" ")));
if (ellipsis) truncatedText += "...";
return truncatedText;
};