added projects
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
rei
2022-12-29 13:42:04 +01:00
parent 446c4a4241
commit e545a596ec
9 changed files with 474 additions and 32 deletions

10
utils/general.ts Normal file
View File

@@ -0,0 +1,10 @@
export const formatDate = (date: string) => {
if (!date) return null;
const [day, month, year] = date.split(".");
const d = new Date(`${year}-${month}-${day}`);
return d.toLocaleDateString("en-US", {
month: "long",
day: "numeric",
year: "numeric",
});
};

View File

@@ -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];
}, []);