Skip to content

Commit 9e50d82

Browse files
fix(routing): Make MDX file lookup more robust
Instead of constructing a strict relative path string which can be brittle, we now search the import.meta.glob keys for one that ends with the requested slug.
1 parent 6c6690d commit 9e50d82

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/pages/NoteView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ const modules = import.meta.glob('../content/notes/*.mdx');
1212
const NoteView: React.FC = () => {
1313
const { slug } = useParams();
1414

15-
const path = `../content/notes/${slug}.mdx`;
16-
const loader = modules[path];
15+
// Robustly find the module that matches the slug
16+
const moduleEntry = Object.entries(modules).find(([path]) => path.endsWith(`/${slug}.mdx`));
17+
const loader = moduleEntry?.[1];
1718

1819
if (!loader) {
1920
return (
2021
<Container sx={{ mt: 10 }}>
2122
<Typography variant="h4">Note not found</Typography>
23+
<Typography color="gray" sx={{ mt: 1 }}>Debug: looked for {slug}.mdx</Typography>
2224
<Button component={Link} to="/notes" sx={{ mt: 2 }}>Back to Notes</Button>
2325
</Container>
2426
);
2527
}
2628

27-
const NoteContent = React.useMemo(() => React.lazy(loader as any), [path]);
29+
const NoteContent = React.useMemo(() => React.lazy(loader as any), [loader]);
2830

2931
return (
3032
<PythonProvider>

0 commit comments

Comments
 (0)