From c4a99f04a7129caf3d0fbc6d8c6fa97aad8e8cb9 Mon Sep 17 00:00:00 2001 From: aeolian <94939382+aeolianeth@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:15:13 +1000 Subject: [PATCH] fix: strip html from seo descriptions --- src/hooks/useSubtitle.ts | 5 +---- src/pages/v2/p/[projectId]/index.tsx | 7 ++++++- src/utils/string.ts | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/utils/string.ts diff --git a/src/hooks/useSubtitle.ts b/src/hooks/useSubtitle.ts index 9e9a6d55c0..4d38cb484d 100644 --- a/src/hooks/useSubtitle.ts +++ b/src/hooks/useSubtitle.ts @@ -1,5 +1,6 @@ import { ProjectMetadata } from 'models/projectMetadata' import { useMemo } from 'react' +import { stripHtmlTags } from 'utils/string' export type SubtitleType = 'tagline' | 'description' @@ -31,7 +32,3 @@ export const useSubtitle = ( return subtitle } - -const stripHtmlTags = (html: string): string => { - return html.replace(/<[^>]*>/g, '') -} diff --git a/src/pages/v2/p/[projectId]/index.tsx b/src/pages/v2/p/[projectId]/index.tsx index 0e0bcc8d70..df8cc37fbd 100644 --- a/src/pages/v2/p/[projectId]/index.tsx +++ b/src/pages/v2/p/[projectId]/index.tsx @@ -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') { @@ -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', diff --git a/src/utils/string.ts b/src/utils/string.ts new file mode 100644 index 0000000000..a24363ee0e --- /dev/null +++ b/src/utils/string.ts @@ -0,0 +1,3 @@ +export const stripHtmlTags = (html: string): string => { + return html.replace(/<[^>]*>/g, '') +}