Skip to content

Commit 7c26e88

Browse files
committed
feat: hide versioned pages in sidebar
1 parent 6e2ce56 commit 7c26e88

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

app/[[...path]]/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {isDeveloperDocs} from 'sentry-docs/isDeveloperDocs';
1919
import {getDevDocsFrontMatter, getDocsFrontMatter, getFileBySlug} from 'sentry-docs/mdx';
2020
import {mdxComponents} from 'sentry-docs/mdxComponents';
2121
import {setServerContext} from 'sentry-docs/serverContext';
22+
import {VERSION_INDICATOR} from 'sentry-docs/versioning';
2223

2324
export async function generateStaticParams() {
2425
const docs = await (isDeveloperDocs ? getDevDocsFrontMatter() : getDocsFrontMatter());
@@ -112,10 +113,13 @@ export default async function Page({params}: {params: {path?: string[]}}) {
112113
// collect versioned files
113114
const versions = (await getDocsFrontMatter())
114115
.filter(({slug}) => {
115-
return slug.includes('__v') && slug.includes(pageNode.path.split('__v')[0]);
116+
return (
117+
slug.includes(VERSION_INDICATOR) &&
118+
slug.includes(pageNode.path.split(VERSION_INDICATOR)[0])
119+
);
116120
})
117121
.map(({slug}) => {
118-
const segments = slug.split('__v');
122+
const segments = slug.split(VERSION_INDICATOR);
119123
return segments[segments.length - 1];
120124
});
121125

src/components/dynamicNav.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Fragment} from 'react';
22

33
import {serverContext} from 'sentry-docs/serverContext';
44
import {sortPages} from 'sentry-docs/utils';
5+
import {VERSION_INDICATOR} from 'sentry-docs/versioning';
56

67
import {NavChevron} from './sidebar/navChevron';
78
import {SidebarLink} from './sidebarLink';
@@ -35,19 +36,22 @@ export const toTree = (nodeList: Node[]): EntityTree[] => {
3536
.sort((a, b) => a.path.localeCompare(b.path))
3637
.forEach(node => {
3738
let curPath = '';
38-
node.path.split('/').reduce((r, name: string) => {
39-
curPath += `${name}/`;
40-
if (!r[name]) {
41-
r[name] = {result: []};
42-
r.result.push({
43-
name,
44-
children: r[name].result,
45-
node: curPath === node.path ? node : null,
46-
});
47-
}
48-
49-
return r[name];
50-
}, level);
39+
// hide versioned pages in sidebar
40+
if (!node.path.includes(VERSION_INDICATOR)) {
41+
node.path.split('/').reduce((r, name: string) => {
42+
curPath += `${name}/`;
43+
if (!r[name]) {
44+
r[name] = {result: []};
45+
r.result.push({
46+
name,
47+
children: r[name].result,
48+
node: curPath === node.path ? node : null,
49+
});
50+
}
51+
52+
return r[name];
53+
}, level);
54+
}
5155
});
5256

5357
result.length; // result[0] is undefined without this. wat

src/components/versionSelector/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ 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 {VERSION_INDICATOR} from 'sentry-docs/versioning';
8+
79
import styles from './style.module.scss';
810

911
const stripTrailingSlash = (url: string) => {
1012
return url.replace(/\/$/, '');
1113
};
1214

13-
const VERSION_INDICATOR = '__v';
14-
1515
export function VersionSelector({versions}: {versions: string[]}) {
1616
const availableVersions = ['latest', ...versions];
1717
const router = useRouter();

src/versioning.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const VERSION_INDICATOR = '__v';

0 commit comments

Comments
 (0)