File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 11import matter from 'gray-matter' ;
22import fs from 'fs' ;
3+ import path from 'path' ;
34
45const getPostContent = ( slug : string ) => {
5- const folder = 'posts/' ;
6- const file = `${ folder } ${ slug } .md` ;
6+ const file = path . join ( process . cwd ( ) , 'posts' , `${ slug } .md` ) ;
77 const content = fs . readFileSync ( file , 'utf8' ) ;
88 const matterResult = matter ( content ) ;
99 // Remove the orig property (Uint8Array) which can't be serialized
Original file line number Diff line number Diff line change 11import * as fs from 'fs' ;
2+ import path from 'path' ;
23
34import matter from 'gray-matter' ;
45import { PostMetadata } from '../components/PostMetadata' ;
56
67const getPostMetadata = ( getDrafts : boolean = false ) : PostMetadata [ ] => {
7- const folder = getDrafts ? 'posts/drafts/' : 'posts/' ;
8- ( 'posts/' ) ;
8+ const folder = getDrafts
9+ ? path . join ( process . cwd ( ) , 'posts' , 'drafts' )
10+ : path . join ( process . cwd ( ) , 'posts' ) ;
911 const files = fs . readdirSync ( folder ) ;
1012 const markdownPosts = files . filter ( ( file ) => file . endsWith ( '.md' ) ) ;
1113
1214 const posts : PostMetadata [ ] = markdownPosts . map (
1315 ( fileName ) : Partial < PostMetadata > => {
1416 try {
15- const fileContents = fs . readFileSync ( ` ${ folder } ${ fileName } ` , 'utf8' ) ;
17+ const fileContents = fs . readFileSync ( path . join ( folder , fileName ) , 'utf8' ) ;
1618 const matterResult = matter ( fileContents ) ;
1719
1820 return {
You can’t perform that action at this time.
0 commit comments