Skip to content

Commit 72d91d1

Browse files
committed
fix post directory
1 parent 930854a commit 72d91d1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

utils/getPostContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import matter from 'gray-matter';
22
import fs from 'fs';
3+
import path from 'path';
34

45
const 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

utils/getPostMetadata.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import * as fs from 'fs';
2+
import path from 'path';
23

34
import matter from 'gray-matter';
45
import { PostMetadata } from '../components/PostMetadata';
56

67
const 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 {

0 commit comments

Comments
 (0)