Skip to content

Commit efdf8e5

Browse files
Tb/wrfl 1834 update (#262)
* updated mdx-utils.js and [slug].js * updated public directory
1 parent 8147133 commit efdf8e5

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

pages/posts/[slug].js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
getNextPostBySlug,
44
getPostBySlug,
55
getPreviousPostBySlug,
6-
postFilePaths,
6+
getPostFilePaths,
77
} from '../../utils/mdx-utils';
88

99
import { MDXRemote } from 'next-mdx-remote';
@@ -124,7 +124,7 @@ export const getStaticProps = async ({ params }) => {
124124
};
125125

126126
export const getStaticPaths = async () => {
127-
const paths = postFilePaths
127+
const paths = getPostFilePaths()
128128
// Remove file extensions for page paths
129129
.map((path) => path.replace(/\.mdx?$/, ''))
130130
// Map the path into the static paths object required by Next.js

public/images/nextjs.svg

Lines changed: 1 addition & 0 deletions
Loading

utils/mdx-utils.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import remarkGfm from 'remark-gfm';
88
// POSTS_PATH is useful when you want to get the path to a specific file
99
export const POSTS_PATH = path.join(process.cwd(), 'posts');
1010

11-
// postFilePaths is the list of all mdx files inside the POSTS_PATH directory
12-
export const postFilePaths = fs
13-
.readdirSync(POSTS_PATH)
14-
// Only include md(x) files
15-
.filter((path) => /\.mdx?$/.test(path));
11+
// getPostFilePaths is the list of all mdx files inside the POSTS_PATH directory
12+
export const getPostFilePaths = () => {
13+
return fs.readdirSync(POSTS_PATH)
14+
// Only include md(x) files
15+
.filter((path) => /\.mdx?$/.test(path));
16+
};
1617

1718
export const sortPostsByDate = (posts) => {
1819
return posts.sort((a, b) => {
@@ -23,7 +24,7 @@ export const sortPostsByDate = (posts) => {
2324
};
2425

2526
export const getPosts = () => {
26-
let posts = postFilePaths.map((filePath) => {
27+
let posts = getPostFilePaths().map((filePath) => {
2728
const source = fs.readFileSync(path.join(POSTS_PATH, filePath));
2829
const { content, data } = matter(source);
2930

0 commit comments

Comments
 (0)