Skip to content

Commit

Permalink
[QA-1342] Fix default SSR tags (#8719)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Jun 10, 2024
1 parent 9bb365d commit ffc4083
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/web/src/components/meta-tags/MetaTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type MetaTagsProps = {
*/
ogDescription?: string
image?: string
imageAlt?: string
canonicalUrl?: string
structuredData?: object
noIndex?: boolean
Expand All @@ -31,6 +32,7 @@ export const MetaTags = (props: MetaTagsProps) => {
description,
ogDescription,
image,
imageAlt,
canonicalUrl,
structuredData,
noIndex = false
Expand Down Expand Up @@ -87,6 +89,13 @@ export const MetaTags = (props: MetaTagsProps) => {
</Helmet>
) : null}

{imageAlt ? (
<Helmet encodeSpecialCharacters={false}>
<meta name='twitter:image:alt' content={imageAlt} />
<meta name='og:image:alt' content={imageAlt} />
</Helmet>
) : null}

<Helmet encodeSpecialCharacters={false}>
<meta property='og:type' content='website' />
<meta name='twitter:card' content='summary' />
Expand Down
25 changes: 25 additions & 0 deletions packages/web/src/ssr/index/+onRenderHtml.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
// For all routes except the explicitly defined ones
// simply render the SPA without SSR

import { renderToString } from 'react-dom/server'
import { Helmet } from 'react-helmet'
import { escapeInject, dangerouslySkipEscape } from 'vike/server'

import { MetaTags } from 'components/meta-tags/MetaTags'
import { getIndexHtml } from 'ssr/getIndexHtml'
import { getDefaultSEOFields } from 'utils/seo'

export function render() {
const seoMetadata = getDefaultSEOFields()

const pageHtml = renderToString(
<>
<MetaTags {...seoMetadata} />
<div />
</>
)

const helmet = Helmet.renderStatic()

const html = getIndexHtml()
.replace(`<div id="root"></div>`, `<div id="root">${pageHtml}</div>`)
.replace(
`<meta property="helmet" />`,
`
${helmet.title.toString()}
${helmet.meta.toString()}
${helmet.link.toString()}
`
)

return escapeInject`${dangerouslySkipEscape(html)}`
}
10 changes: 10 additions & 0 deletions packages/web/src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,13 @@ export const getCollectionPageSEOFields = ({
structuredData
}
}

export const getDefaultSEOFields = () => ({
title: 'Audius - Empowering Creators',
description:
'Audius is a music streaming and sharing platform that puts power back into the hands of content creators.',
ogDescription:
'Audius is a music streaming and sharing platform that puts power back into the hands of content creators.',
image: 'https://audius.co/ogImage.jpg',
imageAlt: 'The Audius Platform'
})

0 comments on commit ffc4083

Please sign in to comment.