Skip to content

Commit 5c60bba

Browse files
committed
fix: version fallback platforms
1 parent 776f87a commit 5c60bba

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

src/components/platformContent.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {getCurrentGuide, getDocsRootNode, getPlatform} from 'sentry-docs/docTree
77
import {getFileBySlug} from 'sentry-docs/mdx';
88
import {mdxComponents} from 'sentry-docs/mdxComponents';
99
import {serverContext} from 'sentry-docs/serverContext';
10-
import {isVersioned, stripVersion} from 'sentry-docs/versioning';
10+
import {
11+
getVersion,
12+
isVersioned,
13+
stripVersion,
14+
VERSION_INDICATOR,
15+
} from 'sentry-docs/versioning';
1116

1217
import {Include} from './include';
1318

@@ -55,6 +60,7 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)
5560
const guidePath = udpatePathIfVersionedFileDoesNotExist(
5661
`platform-includes/${includePath}/${guide}`
5762
);
63+
5864
try {
5965
doc = await getFileBySlug(guidePath);
6066
} catch (e) {
@@ -67,7 +73,7 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)
6773
const guideObject = getCurrentGuide(rootNode, path);
6874

6975
const fallbackGuidePath = udpatePathIfVersionedFileDoesNotExist(
70-
`platform-includes/${includePath}/${guideObject?.fallbackGuide}`
76+
`platform-includes/${includePath}/${guideObject?.fallbackGuide}${VERSION_INDICATOR}${getVersion(guide || '')}`
7177
);
7278

7379
if (guideObject?.fallbackGuide) {

src/components/versionSelector/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import {ChevronDownIcon} from '@radix-ui/react-icons';
44
import * as RadixSelect from '@radix-ui/react-select';
55
import {usePathname, useRouter} from 'next/navigation';
66

7+
import {stripTrailingSlash} from 'sentry-docs/utils';
78
import {getLocalStorageVersionKey, VERSION_INDICATOR} from 'sentry-docs/versioning';
89

910
import styles from './style.module.scss';
1011

1112
import {VersionBanner} from '../versionBanner';
1213

13-
const stripTrailingSlash = (url: string) => {
14-
return url.replace(/\/$/, '');
15-
};
16-
1714
export function VersionSelector({versions, sdk}: {sdk: string; versions: string[]}) {
1815
const availableVersions = ['latest', ...versions];
1916
const router = useRouter();

src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ export function isTruthy<T>(value: T | undefined | null): value is T {
9494
}
9595

9696
export const isLocalStorageAvailable = () => typeof localStorage !== 'undefined';
97+
98+
export const stripTrailingSlash = (url: string) => {
99+
return url.replace(/\/$/, '');
100+
};

src/versioning.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {describe, expect, test} from 'vitest';
22

3-
import {getUnversionedPath} from './versioning';
3+
import {getUnversionedPath, getVersion} from './versioning';
44

55
describe('versioning', () => {
66
test('should return unversioned paths', () => {
@@ -11,4 +11,10 @@ describe('versioning', () => {
1111
expect(getUnversionedPath(['some', 'path__v2'])).toBe('some/path/');
1212
expect(getUnversionedPath(['some', 'path__v2'], false)).toBe('some/path');
1313
});
14+
15+
test('should return version from slug', () => {
16+
expect(getVersion('/')).toBe('');
17+
expect(getVersion('/some/path__v7.x')).toBe('7.x');
18+
expect(getVersion('/some/path__v7.x/')).toBe('7.x');
19+
});
1420
});

src/versioning.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {stripTrailingSlash} from './utils';
2+
13
export const VERSION_INDICATOR = '__v';
24

35
export const getLocalStorageVersionKey = (platform: string) => `version:${platform}`;
@@ -14,3 +16,11 @@ export const getUnversionedPath = (path: string | string[], trailingSlash = true
1416
export const isVersioned = (path: string) => path.includes(VERSION_INDICATOR);
1517

1618
export const stripVersion = (path: string) => path.split(VERSION_INDICATOR)[0];
19+
20+
export const getVersion = (path: string) => {
21+
const version = path.split(VERSION_INDICATOR)[1];
22+
if (!version) {
23+
return '';
24+
}
25+
return stripTrailingSlash(version);
26+
};

0 commit comments

Comments
 (0)