From ade397fc241396037532eddf139694eba3e6064f Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 15 Feb 2023 11:16:14 +0100 Subject: [PATCH] web/user: revert truncate behaviour for application description Signed-off-by: Jens Langhammer --- web/src/common/utils.ts | 14 ++++++++++++++ web/src/user/LibraryApplication.ts | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/web/src/common/utils.ts b/web/src/common/utils.ts index 1d26396b1..c016e7fd6 100644 --- a/web/src/common/utils.ts +++ b/web/src/common/utils.ts @@ -29,6 +29,20 @@ export function convertToTitle(text: string): string { }); } +/** + * Truncate a string based on maximum word count + */ +export function truncateWords(string: string, length = 10): string { + string = string || ""; + const array = string.trim().split(" "); + const ellipsis = array.length > length ? "..." : ""; + + return array.slice(0, length).join(" ") + ellipsis; +} + +/** + * Truncate a string based on character count + */ export function truncate(string: string, length = 10): string { return string.length > length ? `${string.substring(0, length)}...` : string; } diff --git a/web/src/user/LibraryApplication.ts b/web/src/user/LibraryApplication.ts index 6d374dbff..6ad3e75ae 100644 --- a/web/src/user/LibraryApplication.ts +++ b/web/src/user/LibraryApplication.ts @@ -1,6 +1,6 @@ import { uiConfig } from "@goauthentik/common/ui/config"; import { me } from "@goauthentik/common/users"; -import { truncate } from "@goauthentik/common/utils"; +import { truncateWords } from "@goauthentik/common/utils"; import { AKElement } from "@goauthentik/elements/Base"; import { t } from "@lingui/macro"; @@ -127,7 +127,7 @@ export class LibraryApplication extends AKElement {
- ${truncate(this.application.metaDescription || "", 35)} + ${truncateWords(this.application.metaDescription || "", 35)}
`; }