Skip to content

Commit

Permalink
fix: strip html from seo descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
aeolianeth committed Jul 3, 2024
1 parent cc55995 commit c4a99f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/hooks/useSubtitle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ProjectMetadata } from 'models/projectMetadata'
import { useMemo } from 'react'
import { stripHtmlTags } from 'utils/string'

export type SubtitleType = 'tagline' | 'description'

Expand Down Expand Up @@ -31,7 +32,3 @@ export const useSubtitle = (

return subtitle
}

const stripHtmlTags = (html: string): string => {
return html.replace(/<[^>]*>/g, '')
}
7 changes: 6 additions & 1 deletion src/pages/v2/p/[projectId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ProjectPageProps,
getProjectStaticProps,
} from 'utils/server/pages/props'
import { stripHtmlTags } from 'utils/string'

export const getStaticPaths: GetStaticPaths = async () => {
if (process.env.BUILD_CACHE_V2_PROJECTS === 'true') {
Expand Down Expand Up @@ -69,7 +70,11 @@ const ProjectPageSEO = ({
title={metadata?.name}
url={`${SiteBaseUrl}v2/p/${projectId}`}
description={
metadata?.projectTagline ? metadata.projectTagline : metadata?.description
metadata?.projectTagline
? metadata.projectTagline
: metadata?.description
? stripHtmlTags(metadata.description)
: undefined
}
twitter={{
card: 'summary',
Expand Down
3 changes: 3 additions & 0 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const stripHtmlTags = (html: string): string => {
return html.replace(/<[^>]*>/g, '')
}

0 comments on commit c4a99f0

Please sign in to comment.