This commit is contained in:
12
lib/blog.ts
12
lib/blog.ts
@@ -40,7 +40,7 @@ export async function markdownToHTML(markdown: string) {
|
||||
|
||||
export async function getPost(slug: string) {
|
||||
const filePath = path.join("content", `${slug}.mdx`);
|
||||
let source = fs.readFileSync(filePath, "utf-8");
|
||||
const source = fs.readFileSync(filePath, "utf-8");
|
||||
const { content: rawContent, data: metadata } = matter(source);
|
||||
const content = await markdownToHTML(rawContent);
|
||||
return {
|
||||
@@ -51,14 +51,14 @@ export async function getPost(slug: string) {
|
||||
}
|
||||
|
||||
async function getAllPosts(dir: string, category?: string) {
|
||||
let mdxFiles = getMDXFiles(dir);
|
||||
const mdxFiles = getMDXFiles(dir);
|
||||
console.log(dir);
|
||||
console.log(category);
|
||||
console.log(mdxFiles);
|
||||
const posts = await Promise.all(
|
||||
mdxFiles.map(async (file) => {
|
||||
let slug = path.basename(file, path.extname(file));
|
||||
let { metadata, source } = await getPost(slug);
|
||||
const slug = path.basename(file, path.extname(file));
|
||||
const { metadata, source } = await getPost(slug);
|
||||
console.log(file);
|
||||
console.log(slug);
|
||||
console.log(metadata);
|
||||
@@ -79,8 +79,8 @@ async function getAllPosts(dir: string, category?: string) {
|
||||
return posts;
|
||||
}
|
||||
|
||||
export async function getBlogPosts(category?: string) {
|
||||
let postPath = path.join(process.cwd(), "content");
|
||||
export async function getPosts(category?: string) {
|
||||
const postPath = path.join(process.cwd(), "content");
|
||||
console.log(postPath);
|
||||
return getAllPosts(postPath, category);
|
||||
}
|
||||
Reference in New Issue
Block a user