-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fixing JS framework formatting for redirect pages #14914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sfanahata
wants to merge
7
commits into
master
Choose a base branch
from
platform-redirect-privacy-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5affddc
fixing JS framework formatting for redirect pages
3fe281a
fixing bugs
d39eb3a
[getsentry/action-github-commit] Auto commit
getsantry[bot] 6434309
genericizing the solution and cleaning up filter logic, improve visua…
4498f81
[getsentry/action-github-commit] Auto commit
getsantry[bot] adbbfa9
Merge remote-tracking branch 'origin/master' into platform-redirect-p…
5e3688b
Merge branch 'platform-redirect-privacy-fix' of https://github.com/ge…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,35 +37,104 @@ export default async function Page(props: { | |
| "The page you are looking for is customized for each platform. Select your platform below and we'll direct you to the most specific documentation on it."; | ||
| let title = defaultTitle; | ||
|
|
||
| // get rid of irrelevant platforms for the `next` path | ||
| const platformList = extractPlatforms(rootNode).filter(platform_ => { | ||
| const node = nodeForPath(rootNode, [ | ||
| // Build a list of platforms or guides that have the content for the `next` path | ||
| type PlatformOrGuide = { | ||
| icon: string; | ||
| key: string; | ||
| title: string; | ||
| url: string; | ||
| isGuide?: boolean; | ||
| parentPlatform?: string; | ||
| }; | ||
|
|
||
| const platformOrGuideList: PlatformOrGuide[] = []; | ||
|
|
||
| for (const platformEntry of extractPlatforms(rootNode)) { | ||
| // Check if the main platform path has the content | ||
| const mainPlatformNode = nodeForPath(rootNode, [ | ||
| 'platforms', | ||
| platform_.key, | ||
| platformEntry.key, | ||
| ...pathname.split('/').filter(Boolean), | ||
| ]); | ||
|
|
||
| // extract title and description for displaying it on page | ||
| if (node && title === defaultTitle && pathname.length > 0) { | ||
| title = node.frontmatter.title ?? title; | ||
| description = node.frontmatter.description || ''; | ||
| // Extract title and description from the first valid node we find | ||
| if (mainPlatformNode && title === defaultTitle && pathname.length > 0) { | ||
| title = mainPlatformNode.frontmatter.title ?? title; | ||
| description = mainPlatformNode.frontmatter.description || ''; | ||
| } | ||
|
|
||
| // Check which guides have the content | ||
| const supportedGuides: typeof platformEntry.guides = []; | ||
| if (platformEntry.guides) { | ||
| for (const guide of platformEntry.guides) { | ||
| const guideNode = nodeForPath(rootNode, [ | ||
| 'platforms', | ||
| platformEntry.key, | ||
| 'guides', | ||
| guide.name, | ||
| ...pathname.split('/').filter(Boolean), | ||
| ]); | ||
|
|
||
| if (guideNode) { | ||
| supportedGuides.push(guide); | ||
|
|
||
| // Extract title and description if we haven't yet | ||
| if (title === defaultTitle && pathname.length > 0) { | ||
| title = guideNode.frontmatter.title ?? title; | ||
| description = guideNode.frontmatter.description || ''; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return !!node; | ||
| }); | ||
| // Check notSupported list to filter out unsupported guides (for platforms like JavaScript) | ||
| let filteredGuides = supportedGuides; | ||
| if (mainPlatformNode?.frontmatter.notSupported && supportedGuides.length > 0) { | ||
| const notSupported = mainPlatformNode.frontmatter.notSupported; | ||
| filteredGuides = supportedGuides.filter( | ||
| guide => !notSupported.includes(`${platformEntry.key}.${guide.name}`) | ||
| ); | ||
| } | ||
|
|
||
| // Include platform if main path exists OR if any guides exist | ||
| if (mainPlatformNode || filteredGuides.length > 0) { | ||
| // Add the main platform entry only if it has content | ||
| if (mainPlatformNode) { | ||
| platformOrGuideList.push({ | ||
| key: platformEntry.key, | ||
| title: platformEntry.title ?? platformEntry.key ?? '', | ||
| url: platformEntry.url ?? '', | ||
| icon: platformEntry.icon ?? platformEntry.key, | ||
| }); | ||
| } | ||
|
|
||
| // Add guide entries as nested items (only if main platform exists) | ||
| // or as top-level items (if only guides have content) | ||
| for (const guide of filteredGuides) { | ||
| platformOrGuideList.push({ | ||
| key: `${platformEntry.key}.${guide.name}`, | ||
| title: guide.title ?? guide.name ?? '', | ||
| url: guide.url ?? '', // Always use the guide-specific URL | ||
| icon: `${platformEntry.key}-${guide.name}`, | ||
| isGuide: mainPlatformNode ? true : false, // Only nest if parent exists | ||
| parentPlatform: platformEntry.key, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (platformList.length === 0) { | ||
| if (platformOrGuideList.length === 0) { | ||
| // try to redirect the user to the page directly, might result in 404 | ||
| return redirect(next); | ||
| } | ||
|
|
||
| const requestedPlatform = Array.isArray(platform) ? platform[0] : platform; | ||
| if (requestedPlatform) { | ||
| const isValidPlatform = platformList.some( | ||
| const validPlatform = platformOrGuideList.find( | ||
| p => p.key === requestedPlatform?.toLowerCase() | ||
| ); | ||
| if (isValidPlatform) { | ||
| return redirect(`/platforms/${requestedPlatform}${pathname}`); | ||
| if (validPlatform) { | ||
| return redirect(`${validPlatform.url}${pathname}`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Malformed URLs Break NavigationThe Additional Locations (1) |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -82,12 +151,12 @@ export default async function Page(props: { | |
| <Alert>{platformInfo}</Alert> | ||
|
|
||
| <ul> | ||
| {platformList.map(p => ( | ||
| <li key={p.key}> | ||
| <SmartLink to={`/platforms/${p.key}${pathname}`}> | ||
| {platformOrGuideList.map(p => ( | ||
| <li key={p.key} style={{marginLeft: p.isGuide ? '20px' : '0'}}> | ||
| <SmartLink to={`${p.url}${pathname}`}> | ||
| <PlatformIcon | ||
| size={16} | ||
| platform={p.icon ?? p.key} | ||
| platform={p.icon} | ||
| style={{marginRight: '0.5rem'}} | ||
| format="sm" | ||
| /> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.