This commit is contained in:
@@ -6,8 +6,13 @@ import { remark } from "remark";
|
||||
import html from "remark-html";
|
||||
|
||||
export const BLOGS_PATH = join(process.cwd(), "content/blogs");
|
||||
export const PROJECTS_PATH = join(process.cwd(), "content/projects");
|
||||
export interface Post {
|
||||
frontMatter: FrontMatter;
|
||||
slug: string;
|
||||
}
|
||||
|
||||
export const getFileContentBySlug = (slug: string): MarkdownDocument => {
|
||||
export const getBlogContentBySlug = (slug: string): MarkdownDocument => {
|
||||
const filepath = join(BLOGS_PATH, `${slug}.md` || `${slug}.mdx`);
|
||||
const filecontents = fs.readFileSync(filepath);
|
||||
|
||||
@@ -18,18 +23,34 @@ export const getFileContentBySlug = (slug: string): MarkdownDocument => {
|
||||
content: content,
|
||||
};
|
||||
};
|
||||
export const getProjectContentBySlug = (slug: string): MarkdownDocument => {
|
||||
const filepath = join(PROJECTS_PATH, `${slug}.md` || `${slug}.mdx`);
|
||||
const filecontents = fs.readFileSync(filepath);
|
||||
|
||||
export interface BlogPost {
|
||||
frontMatter: FrontMatter;
|
||||
slug: string;
|
||||
}
|
||||
const { data, content } = matter(filecontents);
|
||||
|
||||
export const getAllFilesFrontMatter = (): BlogPost[] => {
|
||||
return {
|
||||
frontMatter: data,
|
||||
content: content,
|
||||
};
|
||||
};
|
||||
|
||||
export const getAllBlogsFrontMatter = (): Post[] => {
|
||||
const files = fs.readdirSync(BLOGS_PATH);
|
||||
|
||||
return files.reduce((allPosts: BlogPost[], postSlug: string) => {
|
||||
return files.reduce((allPosts: Post[], postSlug: string) => {
|
||||
const slug = postSlug.replace(".md", "");
|
||||
const post = getFileContentBySlug(slug);
|
||||
const post = getBlogContentBySlug(slug);
|
||||
|
||||
return [{ frontMatter: post.frontMatter, slug }, ...allPosts];
|
||||
}, []);
|
||||
};
|
||||
export const getAllProjectsFrontMatter = (): Post[] => {
|
||||
const files = fs.readdirSync(PROJECTS_PATH);
|
||||
|
||||
return files.reduce((allPosts: Post[], postSlug: string) => {
|
||||
const slug = postSlug.replace(".md", "");
|
||||
const post = getProjectContentBySlug(slug);
|
||||
|
||||
return [{ frontMatter: post.frontMatter, slug }, ...allPosts];
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user