Skip to content

Commit 97bd3f4

Browse files
committed
change structure
1 parent b46c886 commit 97bd3f4

File tree

6 files changed

+38
-28
lines changed

6 files changed

+38
-28
lines changed

docs/platforms/javascript/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
title: Browser JavaScript
2-
topLevelAlias: JavaScript
2+
platformTitle: JavaScript
33
caseStyle: camelCase
44
supportLevel: production
55
sdk: 'sentry.javascript.browser'

src/components/breadcrumbs/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function Breadcrumbs({leafNode}: BreadcrumbsProps) {
2323
return (
2424
<li className={styles['breadcrumb-item']} key={n.path}>
2525
<SmartLink to={to}>
26-
{n.frontmatter.topLevelAlias ?? n.frontmatter.title}
26+
{n.frontmatter.platformTitle ?? n.frontmatter.title}
2727
</SmartLink>
2828
</li>
2929
);

src/components/platformFilter/client.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function PlatformFilterClient({platforms}: {platforms: Platform[]}) {
6262
return platformsAndGuides;
6363
}
6464
// any of these fields can be used to match the search value
65-
const keys = ['title', 'aliases', 'name', 'sdk', 'keywords', 'topLevelAlias'];
65+
const keys = ['title', 'aliases', 'name', 'sdk', 'keywords', 'platformTitle'];
6666
const matches_ = matchSorter(platformsAndGuides, filter, {
6767
keys,
6868
threshold: rankings.CONTAINS,
@@ -195,7 +195,14 @@ function PlatformWithGuides({
195195

196196
const guides = useMemo(() => {
197197
const showPlatformInContent = matchKeys.includes(platform.key);
198-
return showPlatformInContent ? [platform, ...platform.guides] : platform.guides;
198+
199+
// This is the case if `platformTitle` is configured for a platform
200+
// In this case, we do not need to add the platform to the list of guides
201+
const hasGuideWithPlatformKey = platform.guides.some(g => g.key === platform.key);
202+
203+
return showPlatformInContent && !hasGuideWithPlatformKey
204+
? [platform, ...platform.guides]
205+
: platform.guides;
199206
}, [matchKeys, platform]);
200207

201208
return (
@@ -213,7 +220,7 @@ function PlatformWithGuides({
213220
format="lg"
214221
className={`${styles.PlatformIcon} !border-none !shadow-none`}
215222
/>
216-
{platform.topLevelAlias ?? platform.title}
223+
{platform.title}
217224
</div>
218225
<button className={styles.ChevronButton}>
219226
<TriangleRightIcon

src/components/platformSelector/index.tsx

+7-15
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,13 @@ function PlatformItem({
279279
isLastGuide: i === guides.length - 1,
280280
}));
281281

282-
const isPlatformWithGuidesAndTopLevelAlias =
283-
platform.guides.length > 0 && !!platform.topLevelAlias;
282+
// This is the case if `platformTitle` is configured for a platform
283+
// In this case, the top-level select item should get the `-redirect` suffix,
284+
// as we can't have two items with the same key
285+
const hasGuideWithPlatformKey = platform.guides.some(g => g.key === platform.key);
284286

285287
const guides = platform.isExpanded
286-
? markLastGuide(
287-
platform.guides.length > 0
288-
? isPlatformWithGuidesAndTopLevelAlias
289-
? [platform as unknown as PlatformGuide, ...platform.guides]
290-
: platform.guides
291-
: platform.integrations
292-
)
288+
? markLastGuide(platform.guides.length > 0 ? platform.guides : platform.integrations)
293289
: [];
294290

295291
return (
@@ -299,11 +295,7 @@ function PlatformItem({
299295
<RadixSelect.Label className="flex">
300296
<Fragment>
301297
<RadixSelect.Item
302-
value={
303-
isPlatformWithGuidesAndTopLevelAlias
304-
? `${platform.key}-redirect`
305-
: platform.key
306-
}
298+
value={hasGuideWithPlatformKey ? `${platform.key}-redirect` : platform.key}
307299
asChild
308300
className={styles.item}
309301
data-platform-with-guides
@@ -318,7 +310,7 @@ function PlatformItem({
318310
format="sm"
319311
className={styles['platform-icon']}
320312
/>
321-
{platform.topLevelAlias ?? platform.title}
313+
{platform.title}
322314
</span>
323315
</RadixSelect.ItemText>
324316
</ComboboxItem>

src/docTree.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,20 @@ function nodeToPlatform(n: DocNode): Platform {
253253
const caseStyle = platformData?.case_style || n.frontmatter.caseStyle;
254254
const guides = extractGuides(n);
255255
const integrations = extractIntegrations(n);
256-
const topLevelAlias = n.frontmatter.topLevelAlias;
257256

258257
return {
259258
key: n.slug,
260259
name: n.slug,
261260
type: 'platform',
262261
url: '/' + n.path + '/',
263-
title: n.frontmatter.title,
262+
title: n.frontmatter.platformTitle ?? n.frontmatter.title,
264263
caseStyle,
265264
sdk: n.frontmatter.sdk,
266265
fallbackPlatform: n.frontmatter.fallbackPlatform,
267266
categories: n.frontmatter.categories,
268267
keywords: n.frontmatter.keywords,
269268
guides,
270269
integrations,
271-
topLevelAlias,
272270
};
273271
}
274272

@@ -371,9 +369,20 @@ function extractGuides(platformNode: DocNode): PlatformGuide[] {
371369
if (!guidesNode) {
372370
return [];
373371
}
374-
return guidesNode.children
372+
373+
// If a `platformTitle` is defined, we add a virtual guide
374+
const defaultGuide = platformNode.frontmatter.platformTitle
375+
? {
376+
...nodeToGuide(platformNode.slug, platformNode),
377+
key: platformNode.slug,
378+
}
379+
: undefined;
380+
381+
const childGuides = guidesNode.children
375382
.filter(({path}) => !isVersioned(path))
376383
.map(n => nodeToGuide(platformNode.slug, n));
384+
385+
return defaultGuide ? [defaultGuide, ...childGuides] : childGuides;
377386
}
378387

379388
const extractIntegrations = (p: DocNode): PlatformIntegration[] => {

src/types/platform.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ export interface PlatformConfig {
118118
* Keywords used for search etc.
119119
*/
120120
keywords?: string[];
121+
/**
122+
* The title of the platform as it should be displayed in the sidebar.
123+
* In most cases, you do not need to define this, as the title is used.
124+
* However, in some cases - e.g. JavaScript - the Platform title (JavaScript) is different from the default guide (Browser JavaScript).
125+
*/
126+
platformTitle?: string;
121127
/**
122128
* Used to map a platform to a specific SDK as defined by the SDK registry.
123129
*/
@@ -134,10 +140,6 @@ export interface PlatformConfig {
134140
* The human readable name of the platform.
135141
*/
136142
title?: string;
137-
/**
138-
* Alias for the top level platform name.
139-
*/
140-
topLevelAlias?: string;
141143
}
142144

143145
/**

0 commit comments

Comments
 (0)