2023-01-31 13:58:28 +00:00
|
|
|
export const getDescription = (body: string): string => {
|
|
|
|
if (!body) {
|
|
|
|
return ''
|
|
|
|
}
|
2023-01-30 10:39:36 +00:00
|
|
|
const descriptionWordsArray = body
|
2023-01-31 13:58:28 +00:00
|
|
|
.slice(0, 150) // meta description is roughly 155 characters long
|
2023-01-30 10:39:36 +00:00
|
|
|
.replaceAll(/<[^>]*>/g, '')
|
|
|
|
.split(' ')
|
|
|
|
return descriptionWordsArray.splice(0, descriptionWordsArray.length - 1).join(' ') + '...'
|
|
|
|
}
|