Skip to content

Commit e105759

Browse files
leereillyashishkeshanheiskr
authored
Fix broken og:image and twitter:image for 𝕏 (#55353)
Co-authored-by: Ashish Keshan <[email protected]> Co-authored-by: Kevin Heis <[email protected]>
1 parent 06eaa94 commit e105759

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

src/frame/components/DefaultLayout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const DefaultLayout = (props: Props) => {
3030
fullUrl,
3131
status,
3232
} = mainContext
33+
const xHost = mainContext.xHost
3334
const page = mainContext.page!
3435
const { t } = useTranslation(['meta', 'scroll_button'])
3536
const router = useRouter()
@@ -60,7 +61,7 @@ export const DefaultLayout = (props: Props) => {
6061
const metaDescription = page.introPlainText ? page.introPlainText : t('default_description')
6162

6263
const SOCIAL_CATEGORIES = new Set(['code-security', 'actions', 'issues', 'copilot'])
63-
const SOCIAL_CARD_IMG_BASE_URL = '/assets/cb-345/images/social-cards'
64+
const SOCIAL_CARD_IMG_BASE_URL = `${xHost}/assets/cb-345/images/social-cards`
6465

6566
function getCategoryImageUrl(category: string): string {
6667
return `${SOCIAL_CARD_IMG_BASE_URL}/${category}.png`

src/frame/components/context/MainContext.tsx

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type EnterpriseServerReleases = {
8686
}
8787

8888
export type MainContextT = {
89+
allVersions: Record<string, VersionItem>
8990
breadcrumbs: {
9091
product: BreadcrumbT
9192
category?: BreadcrumbT
@@ -96,21 +97,21 @@ export type MainContextT = {
9697
name: string
9798
href: string
9899
}
100+
currentCategory?: string
101+
currentPathWithoutLanguage: string
99102
currentProduct?: ProductT
100103
currentProductName: string
104+
currentProductTree?: ProductTreeNode | null
101105
currentLayoutName?: string
102-
isHomepageVersion: boolean
106+
currentVersion?: string
103107
data: DataT
104-
error: string
105-
currentCategory?: string
106-
relativePath?: string
107108
enterpriseServerReleases: EnterpriseServerReleases
108-
currentPathWithoutLanguage: string
109-
allVersions: Record<string, VersionItem>
110-
currentVersion?: string
111-
currentProductTree?: ProductTreeNode | null
112-
sidebarTree?: ProductTreeNode | null
109+
enterpriseServerVersions: Array<string>
110+
error: string
113111
featureFlags: FeatureFlags
112+
fullUrl: string
113+
isHomepageVersion: boolean
114+
nonEnterpriseDefaultVersion: string
114115
page: {
115116
documentType: string
116117
type?: string
@@ -122,13 +123,10 @@ export type MainContextT = {
122123
noEarlyAccessBanner: boolean
123124
applicableVersions: string[]
124125
} | null
125-
126-
enterpriseServerVersions: Array<string>
127-
128-
nonEnterpriseDefaultVersion: string
129-
126+
relativePath?: string
127+
sidebarTree?: ProductTreeNode | null
130128
status: number
131-
fullUrl: string
129+
xHost?: string
132130
}
133131

134132
// Write down the namespaces from `data/ui.yml` that are used on all pages,
@@ -231,58 +229,53 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
231229
const currentProductName: string = req.context.currentProductName || ''
232230

233231
const props: MainContextT = {
232+
allVersions: minimalAllVersions(req.context.allVersions),
234233
breadcrumbs: req.context.breadcrumbs || {},
235234
communityRedirect: req.context.page?.communityRedirect || {},
235+
currentCategory: req.context.currentCategory || '',
236+
currentLayoutName: req.context.currentLayoutName || null,
237+
currentPathWithoutLanguage: req.context.currentPathWithoutLanguage,
236238
currentProduct,
237239
currentProductName,
238-
isHomepageVersion: req.context.page?.documentType === 'homepage',
239-
error: req.context.error ? req.context.error.toString() : '',
240+
// This is a slimmed down version of `req.context.currentProductTree`
241+
// that only has the minimal titles stuff needed for sidebars and
242+
// any page that is hidden is omitted.
243+
// However, it's not needed on most pages. For example, on article pages,
244+
// you don't need it. It's similar to the minimal product tree but,
245+
// has the full length titles and not just the short titles.
246+
currentProductTree:
247+
(includeFullProductTree && req.context.currentProductTreeTitlesExcludeHidden) || null,
248+
currentVersion: req.context.currentVersion,
240249
data: {
241250
ui,
242-
243251
reusables,
244-
245252
variables: {
246253
release_candidate: {
247254
version: releaseCandidateVersion,
248255
},
249256
},
250257
},
251-
currentCategory: req.context.currentCategory || '',
252-
currentPathWithoutLanguage: req.context.currentPathWithoutLanguage,
253-
page: pageInfo,
254258
enterpriseServerReleases: pick(req.context.enterpriseServerReleases, [
255259
'isOldestReleaseDeprecated',
256260
'oldestSupported',
257261
'nextDeprecationDate',
258262
'supported',
259263
]),
260264
enterpriseServerVersions: req.context.enterpriseServerVersions,
261-
allVersions: minimalAllVersions(req.context.allVersions),
262-
currentVersion: req.context.currentVersion,
263-
// This is a slimmed down version of `req.context.currentProductTree`
264-
// that only has the minimal titles stuff needed for sidebars and
265-
// any page that is hidden is omitted.
266-
// However, it's not needed on most pages. For example, on article pages,
267-
// you don't need it. It's similar to the minimal product tree but,
268-
// has the full length titles and not just the short titles.
269-
currentProductTree:
270-
(includeFullProductTree && req.context.currentProductTreeTitlesExcludeHidden) || null,
265+
error: req.context.error ? req.context.error.toString() : '',
266+
featureFlags: {},
267+
fullUrl: req.protocol + '://' + req.hostname + req.originalUrl, // does not include port for localhost
268+
isHomepageVersion: req.context.page?.documentType === 'homepage',
269+
nonEnterpriseDefaultVersion: req.context.nonEnterpriseDefaultVersion,
270+
page: pageInfo,
271+
relativePath: req.context.page?.relativePath || null,
271272
// The minimal product tree is needed on all pages that depend on
272273
// the product sidebar or the rest sidebar.
273274
sidebarTree: (includeSidebarTree && req.context.sidebarTree) || null,
274-
featureFlags: {},
275-
nonEnterpriseDefaultVersion: req.context.nonEnterpriseDefaultVersion,
276275
status: res.statusCode,
277-
fullUrl: req.protocol + '://' + req.hostname + req.originalUrl, // does not include port for localhost
276+
xHost: req.get('x-host') || '',
278277
}
279278

280-
if (req.context.currentLayoutName) {
281-
props.currentLayoutName = req.context.currentLayoutName
282-
}
283-
if (req.context.page?.relativePath) {
284-
props.relativePath = req.context.page.relativePath
285-
}
286279
return props
287280
}
288281

0 commit comments

Comments
 (0)