From de9f3c17a0cd4dd883ba7d4911dcd838b749d914 Mon Sep 17 00:00:00 2001 From: Jason Karlavige Date: Fri, 1 Dec 2023 10:51:22 -0500 Subject: [PATCH] add function to prep meta description text from description field --- .../communitySpotlightCard/index.js | 37 ++++++++++++++++++- .../communitySpotlightList/index.js | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/website/src/components/communitySpotlightCard/index.js b/website/src/components/communitySpotlightCard/index.js index b134fff7cb9..122edee8f06 100644 --- a/website/src/components/communitySpotlightCard/index.js +++ b/website/src/components/communitySpotlightCard/index.js @@ -1,5 +1,6 @@ import React from 'react' import Link from '@docusaurus/Link'; +import Head from "@docusaurus/Head"; import styles from './styles.module.css'; import imageCacheWrapper from '../../../functions/image-cache-wrapper'; @@ -51,11 +52,26 @@ function CommunitySpotlightCard({ frontMatter, isSpotlightMember = false }) { communityAward } = frontMatter + // Get meta description text + const metaDescription = stripHtml(description) + return ( + {isSpotlightMember && metaDescription ? ( + + + + + ) : null} {communityAward ? (
Community Award Recipient @@ -162,12 +178,12 @@ function CommunitySpotlightCard({ frontMatter, isSpotlightMember = false }) { ); } -// Truncate text +// Truncate description text for community member cards function truncateText(str) { // Max length of string let maxLength = 300 - // Check if anchor link starts within first 300 characters + // Check if anchor link starts within maxLength let hasLinks = false if(str.substring(0, maxLength - 3).match(/(?:]+)>)/gi, "") + + // Strip new lines and return 130 character substring for description + const updatedDesc = strippedHtml + ?.substring(0, maxLength) + ?.replace(/(\r\n|\r|\n)/g, ""); + + return desc?.length > maxLength ? `${updatedDesc}...` : updatedDesc +} + export default CommunitySpotlightCard diff --git a/website/src/components/communitySpotlightList/index.js b/website/src/components/communitySpotlightList/index.js index 6885f5ff2ac..ed0dbf6d653 100644 --- a/website/src/components/communitySpotlightList/index.js +++ b/website/src/components/communitySpotlightList/index.js @@ -36,6 +36,7 @@ function CommunitySpotlightList({ spotlightData }) { {metaTitle} +