Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions app/[[...path]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {useMemo} from 'react';
import {getMDXComponent} from 'mdx-bundler/client';
import {Metadata} from 'next';
import {notFound} from 'next/navigation';
import {MDXRemote} from 'next-mdx-remote/rsc';

import {apiCategories} from 'sentry-docs/build/resolveOpenAPI';
import {ApiCategoryPage} from 'sentry-docs/components/apiCategoryPage';
Expand All @@ -24,6 +23,8 @@
getDocsFrontMatter,
getFileBySlugWithCache,
getVersionsFromDoc,
rehypePlugins,
remarkPlugins,
} from 'sentry-docs/mdx';
import {mdxComponents} from 'sentry-docs/mdxComponents';
import {setServerContext} from 'sentry-docs/serverContext';
Expand All @@ -47,17 +48,16 @@
const mdxComponentsWithWrapper = mdxComponents(
{Include, PlatformContent},
({children, frontMatter, nextPage, previousPage}) => (
<DocPage frontMatter={frontMatter} nextPage={nextPage} previousPage={previousPage}>
<DocPage
frontMatter={frontMatter ?? {}}
nextPage={nextPage}
previousPage={previousPage}
>
{children}
</DocPage>
)
);

function MDXLayoutRenderer({mdxSource, ...rest}) {
const MDXLayout = useMemo(() => getMDXComponent(mdxSource), [mdxSource]);
return <MDXLayout components={mdxComponentsWithWrapper} {...rest} />;
}

export default async function Page(props: {params: Promise<{path?: string[]}>}) {
const params = await props.params;
// get frontmatter of all docs in tree
Expand Down Expand Up @@ -117,15 +117,27 @@
}
throw e;
}
const {mdxSource, frontMatter} = doc;
// const {mdxSource, frontMatter} = doc;
// pass frontmatter tree into sidebar, rendered page + fm into middle, headers into toc
return (
<MDXLayoutRenderer
mdxSource={mdxSource}
frontMatter={frontMatter}
<DocPage
frontMatter={{title: 'TODO'}}
nextPage={nextPage}
previousPage={previousPage}
/>
>
<MDXRemote
source={doc}
components={mdxComponentsWithWrapper}
options={{
mdxOptions: {
// @ts-ignore
remarkPlugins,
// @ts-ignore
rehypePlugins,
},
}}
/>
</DocPage>
);
}

Expand All @@ -146,7 +158,7 @@
// get the MDX for the current doc and render it
let doc: Awaited<ReturnType<typeof getFileBySlugWithCache>>;
try {
doc = await getFileBySlugWithCache(`docs/${pageNode.path}`);
doc = getFileBySlugWithCache(`docs/${pageNode.path}`);
} catch (e) {
if (e.code === 'ENOENT') {
// eslint-disable-next-line no-console
Expand All @@ -155,19 +167,26 @@
}
throw e;
}
const {mdxSource, frontMatter} = doc;

// collect versioned files
const allFm = await getDocsFrontMatter();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const versions = getVersionsFromDoc(allFm, pageNode.path);

Check failure on line 173 in app/[[...path]]/page.tsx

View workflow job for this annotation

GitHub Actions / Lint

'versions' is declared but its value is never read.

// pass frontmatter tree into sidebar, rendered page + fm into middle, headers into toc.
return (
<MDXLayoutRenderer
mdxSource={mdxSource}
frontMatter={{...frontMatter, versions}}
nextPage={nextPage}
previousPage={previousPage}
<MDXRemote
source={doc}
components={mdxComponentsWithWrapper}
options={{
mdxOptions: {
// @ts-ignore
remarkPlugins,
// @ts-ignore
rehypePlugins,
},
}}
// frontMatter={{...{}, versions}}
// nextPage={nextPage}
// previousPage={previousPage}
/>
);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"mermaid": "^11.4.0",
"micromark": "^4.0.0",
"next": "15.1.7",
"next-mdx-remote": "^4.4.1",
"next-mdx-remote": "^5.0.0",
"next-plausible": "^3.12.4",
"next-themes": "^0.3.0",
"nextjs-toploader": "^1.6.6",
Expand Down
30 changes: 17 additions & 13 deletions src/components/include.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import {useMemo} from 'react';
import {getMDXComponent} from 'mdx-bundler/client';
import {MDXRemote} from 'next-mdx-remote/rsc';

import {getFileBySlugWithCache} from 'sentry-docs/mdx';
import {getFileBySlugWithCache, rehypePlugins, remarkPlugins} from 'sentry-docs/mdx';
import {mdxComponents} from 'sentry-docs/mdxComponents';

import {PlatformContent} from './platformContent';

type Props = {
name: string;
};

function MDXLayoutRenderer({mdxSource: source, ...rest}) {
const MDXLayout = useMemo(() => getMDXComponent(source), [source]);
return <MDXLayout components={mdxComponents({Include, PlatformContent})} {...rest} />;
}
type Props = {name: string};

export async function Include({name}: Props) {
let doc: Awaited<ReturnType<typeof getFileBySlugWithCache>>;
Expand All @@ -28,6 +20,18 @@ export async function Include({name}: Props) {
}
throw e;
}
const {mdxSource} = doc;
return <MDXLayoutRenderer mdxSource={mdxSource} />;
return (
<MDXRemote
source={doc}
components={mdxComponents({Include, PlatformContent})}
options={{
mdxOptions: {
// @ts-ignore
remarkPlugins,
// @ts-ignore
rehypePlugins,
},
}}
/>
);
}
37 changes: 22 additions & 15 deletions src/components/platformContent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'fs';

import {cache, useMemo} from 'react';
import {getMDXComponent} from 'mdx-bundler/client';
import {cache} from 'react';
import {MDXRemote} from 'next-mdx-remote/rsc';

import {getCurrentGuide, getDocsRootNode, getPlatform} from 'sentry-docs/docTree';
import {getFileBySlugWithCache} from 'sentry-docs/mdx';
import {getFileBySlugWithCache, rehypePlugins, remarkPlugins} from 'sentry-docs/mdx';
import {mdxComponents} from 'sentry-docs/mdxComponents';
import {serverContext} from 'sentry-docs/serverContext';
import {
Expand Down Expand Up @@ -49,11 +49,6 @@ const updatePathIfVersionedFileDoesNotExistWithCache = cache(
updatePathIfVersionedFileDoesNotExist
);

function MDXLayoutRenderer({mdxSource: source, ...rest}) {
const MDXLayout = useMemo(() => getMDXComponent(source), [source]);
return <MDXLayout components={mdxComponentsWithWrapper} {...rest} />;
}

export async function PlatformContent({includePath, platform, noGuides}: Props) {
const {path} = serverContext();

Expand All @@ -77,7 +72,7 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)
);

try {
doc = await getFileBySlugWithCache(guidePath);
doc = getFileBySlugWithCache(guidePath);
} catch (e) {
// It's fine - keep looking.
}
Expand All @@ -93,7 +88,7 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)

if (guideObject?.fallbackGuide) {
try {
doc = await getFileBySlugWithCache(fallbackGuidePath);
doc = getFileBySlugWithCache(fallbackGuidePath);
} catch (e) {
// It's fine - keep looking.
}
Expand All @@ -106,7 +101,7 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)
`platform-includes/${includePath}/${platform}`
);

doc = await getFileBySlugWithCache(platformPath);
doc = getFileBySlugWithCache(platformPath);
} catch (e) {
// It's fine - keep looking.
}
Expand All @@ -122,7 +117,7 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)

if (platformObject?.fallbackPlatform) {
try {
doc = await getFileBySlugWithCache(fallbackPlatformPath);
doc = getFileBySlugWithCache(fallbackPlatformPath);
} catch (e) {
// It's fine - keep looking.
}
Expand All @@ -131,15 +126,27 @@ export async function PlatformContent({includePath, platform, noGuides}: Props)

if (!doc) {
try {
doc = await getFileBySlugWithCache(`platform-includes/${includePath}/_default`);
doc = getFileBySlugWithCache(`platform-includes/${includePath}/_default`);
} catch (e) {
// Couldn't find anything.
return null;
}
}

const {mdxSource} = doc;
return <MDXLayoutRenderer mdxSource={mdxSource} />;
return (
<MDXRemote
source={doc}
components={mdxComponentsWithWrapper}
options={{
mdxOptions: {
// @ts-ignore
remarkPlugins,
// @ts-ignore
rehypePlugins,
},
}}
/>
);
}

const mdxComponentsWithWrapper = mdxComponents({Include, PlatformContent});
3 changes: 2 additions & 1 deletion src/hotReloadWatcher.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';

import {watch} from 'node:fs/promises';
import {WebSocketServer} from 'ws';

Expand All @@ -9,7 +10,7 @@ export const throttle = (fn, delay) => {
return (...args) => {
const now = Date.now();
if (now - last < delay) {
return;
return () => {};
}
last = now;
return fn(...args);
Expand Down
Loading
Loading