-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Community award badge and meta descriptions #4567
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7c1ab3b
add badge styling
JKarlavige 4547e4b
add communityAward frontmatter property and add examples
JKarlavige de9f3c1
add function to prep meta description text from description field
JKarlavige 97b4f41
remove changes for demo in pr
john-rock 5da4645
Merge branch 'current' into community-award-badge
john-rock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
|
||
|
@@ -47,44 +48,72 @@ function CommunitySpotlightCard({ frontMatter, isSpotlightMember = false }) { | |
jobTitle, | ||
companyName, | ||
organization, | ||
socialLinks | ||
socialLinks, | ||
communityAward | ||
} = frontMatter | ||
|
||
return ( | ||
<SpotlightWrapper isSpotlightMember={isSpotlightMember} frontMatter={frontMatter}> | ||
// Get meta description text | ||
const metaDescription = stripHtml(description) | ||
|
||
return ( | ||
<SpotlightWrapper | ||
isSpotlightMember={isSpotlightMember} | ||
frontMatter={frontMatter} | ||
> | ||
{isSpotlightMember && metaDescription ? ( | ||
<Head> | ||
<meta | ||
name="description" | ||
content={metaDescription} | ||
/> | ||
<meta | ||
property="og:description" | ||
content={metaDescription} | ||
/> | ||
</Head> | ||
) : null} | ||
{communityAward ? ( | ||
<div className={styles.awardBadge}> | ||
<span>Community Award Recipient</span> | ||
</div> | ||
) : null} | ||
{image && ( | ||
<div className={styles.spotlightMemberImgContainer}> | ||
{id && isSpotlightMember ? ( | ||
<img | ||
src={imageCacheWrapper(image)} | ||
alt={title} | ||
/> | ||
<img src={imageCacheWrapper(image)} alt={title} /> | ||
) : ( | ||
<Link to={`/community/spotlight/${id}`} className={styles.spotlightMemberHeader}> | ||
<img | ||
src={imageCacheWrapper(image)} | ||
alt={title} | ||
/> | ||
<Link | ||
to={`/community/spotlight/${id}`} | ||
className={styles.spotlightMemberHeader} | ||
> | ||
<img src={imageCacheWrapper(image)} alt={title} /> | ||
</Link> | ||
)} | ||
</div> | ||
)} | ||
<div className={styles.spotlightMemberContent}> | ||
{!isSpotlightMember && id ? ( | ||
<h2> | ||
<Link to={`/community/spotlight/${id}`} className={`${styles.spotlightMemberHeader} ${styles.spotlightMemberHeaderSmall}`}>{title}</Link> | ||
<Link | ||
to={`/community/spotlight/${id}`} | ||
className={`${styles.spotlightMemberHeader} ${styles.spotlightMemberHeaderSmall}`} | ||
> | ||
{title} | ||
</Link> | ||
</h2> | ||
) : ( | ||
) : ( | ||
<h1 className={styles.spotlightMemberHeader}>{title}</h1> | ||
)} | ||
{pronouns && <div className={styles.spotlightMemberPronouns}>{pronouns}</div>} | ||
|
||
{pronouns && ( | ||
<div className={styles.spotlightMemberPronouns}>{pronouns}</div> | ||
)} | ||
|
||
{isSpotlightMember && ( | ||
<div className={styles.spotlightMemberHeaderContain}> | ||
{(jobTitle || companyName) && ( | ||
<div className={styles.spotlightMemberInfo}> | ||
{jobTitle && jobTitle} | ||
{jobTitle && companyName && ', '} | ||
{jobTitle && companyName && ", "} | ||
{companyName && companyName} | ||
</div> | ||
)} | ||
|
@@ -101,46 +130,60 @@ function CommunitySpotlightCard({ frontMatter, isSpotlightMember = false }) { | |
</div> | ||
)} | ||
{description && !isSpotlightMember && ( | ||
<p className={styles.spotlightMemberDescription} dangerouslySetInnerHTML={{__html: truncateText(description)}} /> | ||
<p | ||
className={styles.spotlightMemberDescription} | ||
dangerouslySetInnerHTML={{ __html: truncateText(description) }} | ||
/> | ||
)} | ||
{socialLinks && isSpotlightMember && socialLinks?.length > 0 && ( | ||
<div className={styles.spotlightMemberSocial}> | ||
{socialLinks.map((item, i) => ( | ||
<> | ||
{item?.name && item?.link && ( | ||
<> | ||
{i !== 0 && ' | '} | ||
<a href={item.link} title={item.name} target='_blank' rel='noreferrer'>{item.name}</a> | ||
{i !== 0 && " | "} | ||
<a | ||
href={item.link} | ||
title={item.name} | ||
target="_blank" | ||
rel="noreferrer" | ||
> | ||
{item.name} | ||
</a> | ||
</> | ||
)} | ||
</> | ||
))} | ||
</div> | ||
)} | ||
{id && !isSpotlightMember && ( | ||
<Link | ||
to={`/community/spotlight/${id}`} | ||
<Link | ||
to={`/community/spotlight/${id}`} | ||
className={styles.spotlightReadMore} | ||
>Read More</Link> | ||
> | ||
Read More | ||
</Link> | ||
)} | ||
</div> | ||
{description && isSpotlightMember && ( | ||
<div className={styles.spotlightMemberDescriptionFull}> | ||
<h2>About</h2> | ||
<p className={styles.spotlightMemberDescription} dangerouslySetInnerHTML={{__html: description}} /> | ||
|
||
<p | ||
className={styles.spotlightMemberDescription} | ||
dangerouslySetInnerHTML={{ __html: description }} | ||
/> | ||
</div> | ||
)} | ||
</SpotlightWrapper> | ||
) | ||
); | ||
} | ||
|
||
// 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(/(?:<a)/g)) { | ||
hasLinks = true | ||
|
@@ -162,4 +205,21 @@ function truncateText(str) { | |
: str | ||
} | ||
|
||
// Strip HTML for meta description | ||
function stripHtml(desc) { | ||
const maxLength = 130 | ||
|
||
if(!desc) return null | ||
|
||
// Remove HTML elements from string | ||
const strippedHtml = desc?.replace(/(<([^>]+)>)/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 | ||
} | ||
Comment on lines
+208
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the 2nd edit adding a new function |
||
|
||
export default CommunitySpotlightCard |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lot of formatting changes here from editing the file, this was the main section updated.