File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 33 getNextPostBySlug ,
44 getPostBySlug ,
55 getPreviousPostBySlug ,
6- postFilePaths ,
6+ getPostFilePaths ,
77} from '../../utils/mdx-utils' ;
88
99import { MDXRemote } from 'next-mdx-remote' ;
@@ -124,7 +124,7 @@ export const getStaticProps = async ({ params }) => {
124124} ;
125125
126126export const getStaticPaths = async ( ) => {
127- const paths = postFilePaths
127+ const paths = getPostFilePaths ( )
128128 // Remove file extensions for page paths
129129 . map ( ( path ) => path . replace ( / \. m d x ? $ / , '' ) )
130130 // Map the path into the static paths object required by Next.js
Original file line number Diff line number Diff 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
99export 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 ) => / \. m d x ? $ / . 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 ) => / \. m d x ? $ / . test ( path ) ) ;
16+ } ;
1617
1718export const sortPostsByDate = ( posts ) => {
1819 return posts . sort ( ( a , b ) => {
@@ -23,7 +24,7 @@ export const sortPostsByDate = (posts) => {
2324} ;
2425
2526export 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
You can’t perform that action at this time.
0 commit comments