Skip to content

Commit 5affddc

Browse files
author
Shannon Anahata
committed
fixing JS framework formatting for redirect pages
1 parent a40949c commit 5affddc

File tree

1 file changed

+102
-18
lines changed

1 file changed

+102
-18
lines changed

app/platform-redirect/page.tsx

Lines changed: 102 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,31 @@ export default async function Page(props: {
3939

4040
// get rid of irrelevant platforms for the `next` path
4141
const platformList = extractPlatforms(rootNode).filter(platform_ => {
42-
const node = nodeForPath(rootNode, [
42+
// First check the main platform path
43+
let node = nodeForPath(rootNode, [
4344
'platforms',
4445
platform_.key,
4546
...pathname.split('/').filter(Boolean),
4647
]);
4748

49+
// If not found, check if it's a guide (like dart/guides/flutter)
50+
if (!node && platform_.guides) {
51+
for (const guide of platform_.guides) {
52+
node = nodeForPath(rootNode, [
53+
'platforms',
54+
platform_.key,
55+
'guides',
56+
guide.name,
57+
...pathname.split('/').filter(Boolean),
58+
]);
59+
if (node) {
60+
// Update the platform URL to point to the guide
61+
platform_.url = guide.url;
62+
break;
63+
}
64+
}
65+
}
66+
4867
// extract title and description for displaying it on page
4968
if (node && title === defaultTitle && pathname.length > 0) {
5069
title = node.frontmatter.title ?? title;
@@ -54,18 +73,78 @@ export default async function Page(props: {
5473
return !!node;
5574
});
5675

57-
if (platformList.length === 0) {
76+
// For JavaScript platforms, also include individual frameworks that support the content
77+
const expandedPlatformList = [...platformList];
78+
79+
// Find JavaScript platform and add its supported frameworks
80+
// Check both the filtered platformList and all platforms to find JavaScript
81+
const javascriptPlatform = platformList.find(p => p.key === 'javascript') ||
82+
extractPlatforms(rootNode).find(p => p.key === 'javascript');
83+
84+
if (javascriptPlatform && (
85+
pathname.startsWith('/session-replay/') ||
86+
pathname.startsWith('/tracing/') ||
87+
pathname.startsWith('/profiling/') ||
88+
pathname.startsWith('/logs/')
89+
)) {
90+
// Get the JavaScript page to check which frameworks are supported
91+
const jsPageNode = nodeForPath(rootNode, [
92+
'platforms',
93+
'javascript',
94+
...pathname.split('/').filter(Boolean),
95+
]);
96+
97+
if (jsPageNode && jsPageNode.frontmatter.notSupported) {
98+
const notSupported = jsPageNode.frontmatter.notSupported;
99+
100+
// Remove JavaScript from the main list temporarily
101+
const otherPlatforms = expandedPlatformList.filter(p => p.key !== 'javascript');
102+
103+
// Add supported JavaScript frameworks as separate entries
104+
const jsFrameworks = [];
105+
javascriptPlatform.guides?.forEach(guide => {
106+
const guideKey = `javascript.${guide.name}`;
107+
if (!notSupported.includes(guideKey)) {
108+
jsFrameworks.push({
109+
key: guideKey,
110+
name: guide.name,
111+
type: 'platform' as const,
112+
url: javascriptPlatform.url,
113+
title: guide.title,
114+
caseStyle: guide.caseStyle,
115+
sdk: guide.sdk,
116+
fallbackPlatform: guide.fallbackPlatform,
117+
language: guide.language,
118+
categories: guide.categories,
119+
keywords: guide.keywords,
120+
guides: [],
121+
integrations: [],
122+
icon: `javascript-${guide.name}`,
123+
});
124+
}
125+
});
126+
127+
// Rebuild the list with JavaScript and its frameworks at the end
128+
expandedPlatformList.length = 0; // Clear the array
129+
expandedPlatformList.push(...otherPlatforms); // Add other platforms first
130+
expandedPlatformList.push(javascriptPlatform); // Add JavaScript platform
131+
expandedPlatformList.push(...jsFrameworks); // Add JavaScript frameworks last
132+
}
133+
}
134+
135+
if (expandedPlatformList.length === 0) {
58136
// try to redirect the user to the page directly, might result in 404
59137
return redirect(next);
60138
}
61139

62140
const requestedPlatform = Array.isArray(platform) ? platform[0] : platform;
63141
if (requestedPlatform) {
64-
const isValidPlatform = platformList.some(
142+
const validPlatform = expandedPlatformList.find(
65143
p => p.key === requestedPlatform?.toLowerCase()
66144
);
67-
if (isValidPlatform) {
68-
return redirect(`/platforms/${requestedPlatform}${pathname}`);
145+
if (validPlatform) {
146+
// Use the platform's URL (which may have been updated to point to a guide)
147+
return redirect(`${validPlatform.url}${pathname}`);
69148
}
70149
}
71150

@@ -82,19 +161,24 @@ export default async function Page(props: {
82161
<Alert>{platformInfo}</Alert>
83162

84163
<ul>
85-
{platformList.map(p => (
86-
<li key={p.key}>
87-
<SmartLink to={`/platforms/${p.key}${pathname}`}>
88-
<PlatformIcon
89-
size={16}
90-
platform={p.icon ?? p.key}
91-
style={{marginRight: '0.5rem'}}
92-
format="sm"
93-
/>
94-
<h4 style={{display: 'inline-block'}}>{p.title}</h4>
95-
</SmartLink>
96-
</li>
97-
))}
164+
{expandedPlatformList.map(p => {
165+
// Check if this is a JavaScript framework (has javascript. prefix)
166+
const isJSFramework = p.key.startsWith('javascript.');
167+
168+
return (
169+
<li key={p.key} style={{marginLeft: isJSFramework ? '20px' : '0'}}>
170+
<SmartLink to={`${p.url}${pathname}`}>
171+
<PlatformIcon
172+
size={16}
173+
platform={p.icon ?? p.key}
174+
style={{marginRight: '0.5rem'}}
175+
format="sm"
176+
/>
177+
<h4 style={{display: 'inline-block'}}>{p.title}</h4>
178+
</SmartLink>
179+
</li>
180+
);
181+
})}
98182
</ul>
99183
</DocPage>
100184
);

0 commit comments

Comments
 (0)