Skip to content

Commit

Permalink
Prevent _default.md being included in [[...markdownPath]].md
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 29, 2023
1 parent 45e472c commit 759bd2c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
File renamed without changes.
8 changes: 7 additions & 1 deletion src/pages/[[...markdownPath]].js
Expand Up @@ -266,7 +266,12 @@ export async function getStaticPaths() {
: res.slice(rootDir.length + 1);
})
);
return files.flat().filter((file) => file.endsWith('.md'));
return (
files
.flat()
// ignores `errors/*.md`, they will be handled by `pages/errors/[error_code].tsx`
.filter((file) => file.endsWith('.md') && !file.startsWith('errors/'))
);
}

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

const files = await getFiles(rootDir);

const paths = files.map((file) => ({
params: {
markdownPath: getSegments(file),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/errors/[error_code].tsx
Expand Up @@ -121,13 +121,13 @@ export const getStaticProps: GetStaticProps<ErrorDecoderProps> = async ({
const mdxComponentNames = Object.keys(MDXComponents);

// Read MDX from the file.
let path = params?.error_code || 'default';
let path = params?.error_code || 'index';
let mdx;
try {
mdx = fs.readFileSync(rootDir + path + '.md', 'utf8');
} catch {
// if error_code.md is not found, fallback to default.md
mdx = fs.readFileSync(rootDir + '/default.md', 'utf8');
mdx = fs.readFileSync(rootDir + '/index.md', 'utf8');
}

// See if we have a cached output first.
Expand Down

0 comments on commit 759bd2c

Please sign in to comment.