Skip to content

Commit a34b88b

Browse files
RonRicardorachmariheiskr
authored
enable category-specific social preview images (#54936)
Co-authored-by: Rachael Sewell <[email protected]> Co-authored-by: Kevin Heis <[email protected]>
1 parent 51feec8 commit a34b88b

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed
358 KB
Loading
301 KB
Loading
519 KB
Loading
285 KB
Loading
344 KB
Loading

src/frame/components/DefaultLayout.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ export const DefaultLayout = (props: Props) => {
5959

6060
const metaDescription = page.introPlainText ? page.introPlainText : t('default_description')
6161

62+
const SOCIAL_CATEGORIES = new Set(['security', 'actions', 'issues', 'copilot'])
63+
const SOCIAL_CARD_IMG_BASE_URL = '/assets/cb-345/images/social-cards'
64+
65+
function getCategoryImageUrl(category: string): string {
66+
return `${SOCIAL_CARD_IMG_BASE_URL}/${category}.png`
67+
}
68+
69+
function getSocialCardImage(): string {
70+
if (currentProduct && SOCIAL_CATEGORIES.has(currentProduct.id)) {
71+
return getCategoryImageUrl(currentProduct.id)
72+
}
73+
return getCategoryImageUrl('default')
74+
}
75+
6276
return (
6377
<DomainNameEditProvider>
6478
<Head>
@@ -111,10 +125,7 @@ export const DefaultLayout = (props: Props) => {
111125
<meta property="og:title" content={page.fullTitle} />
112126
<meta property="og:type" content="article" />
113127
<meta property="og:url" content={fullUrl} />
114-
<meta
115-
property="og:image"
116-
content="https://github.githubassets.com/images/modules/open_graph/github-logo.png"
117-
/>
128+
<meta property="og:image" content={getSocialCardImage()} />
118129
</>
119130
)}
120131
</Head>

0 commit comments

Comments
 (0)