Gui' Blog

Let's enjoy Markdown

Let's enjoy Markdown

Experiencing MarkDown

Well, this project has been featured, initily, it was only a Next project.
Impossible as well to be only a NextJS project without any front end frameword, here it's React.
During the developpement I enjoyed to play with Node, I never did before, I mean, I did, but i only thought it was a server, not a library funny to play with.
Like here :
1import fs from 'fs';
2import path from 'path';
3import matter from 'gray-matter';
4
5const postsDirectory = path.join(process.cwd(), 'posts');
6
7const getPostData = (fileName) => {
8  const filePath = path.join(postsDirectory, fileName);
9  const fileContent = fs.readFileSync(filePath, 'utf-8');
10
11  const { data, content } = matter(fileContent);
12  const postSlug = fileName.replace(/\.md$/, '');
13  const postData = { slug: postSlug, ...data, content };
14
15  return postData;
16};
17
A 'Simple' function, to parse a file into an object that you can play with