Skip to content

Commit 759bd2c

Browse files
committed
Prevent _default.md being included in [[...markdownPath]].md
1 parent 45e472c commit 759bd2c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
File renamed without changes.

src/pages/[[...markdownPath]].js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ export async function getStaticPaths() {
266266
: res.slice(rootDir.length + 1);
267267
})
268268
);
269-
return files.flat().filter((file) => file.endsWith('.md'));
269+
return (
270+
files
271+
.flat()
272+
// ignores `errors/*.md`, they will be handled by `pages/errors/[error_code].tsx`
273+
.filter((file) => file.endsWith('.md') && !file.startsWith('errors/'))
274+
);
270275
}
271276

272277
// 'foo/bar/baz.md' -> ['foo', 'bar', 'baz']
@@ -280,6 +285,7 @@ export async function getStaticPaths() {
280285
}
281286

282287
const files = await getFiles(rootDir);
288+
283289
const paths = files.map((file) => ({
284290
params: {
285291
markdownPath: getSegments(file),

src/pages/errors/[error_code].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ export const getStaticProps: GetStaticProps<ErrorDecoderProps> = async ({
121121
const mdxComponentNames = Object.keys(MDXComponents);
122122

123123
// Read MDX from the file.
124-
let path = params?.error_code || 'default';
124+
let path = params?.error_code || 'index';
125125
let mdx;
126126
try {
127127
mdx = fs.readFileSync(rootDir + path + '.md', 'utf8');
128128
} catch {
129129
// if error_code.md is not found, fallback to default.md
130-
mdx = fs.readFileSync(rootDir + '/default.md', 'utf8');
130+
mdx = fs.readFileSync(rootDir + '/index.md', 'utf8');
131131
}
132132

133133
// See if we have a cached output first.

0 commit comments

Comments
 (0)