All checks were successful
continuous-integration/drone/push Build is passing
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { GetStaticPaths, GetStaticProps } from "next";
|
|
import fs from "fs";
|
|
import { ParsedUrlQuery } from "querystring";
|
|
import { getProjectContentBySlug, PROJECTS_PATH } from "../../utils/markdown";
|
|
import { MarkdownRenderingResult } from "../../types/types";
|
|
import { MainLayout } from "../../layouts/MainLayout";
|
|
import Link from "next/link";
|
|
import { IoMdArrowRoundBack as BackIcon } from "react-icons/io";
|
|
import { readingTime } from "../../utils/general";
|
|
import { PostHeader } from "../../components/PostHeader";
|
|
import { StyledMarkdown } from "../../components/StyledMarkdown";
|
|
|
|
export const ProjectArticle = ({
|
|
frontMatter,
|
|
html,
|
|
}: MarkdownRenderingResult) => {
|
|
return (
|
|
<MainLayout>
|
|
<div className="rounded-md border border-gray-200 shadow-md shadow-gray-200 dark:shadow-gray-900 dark:border-gray-700 gap-4 bg-black bg-opacity-30 round">
|
|
<div className="mx-10 my-10">
|
|
<Link href="/projects">
|
|
<button className="flex flex-row items-center gap-2 text-primary hover:text-primary-dark dark:text-secondary dark:hover:text-secondary/50 transition-all ease-in duration-75">
|
|
<BackIcon />
|
|
<span>Go Back</span>
|
|
</button>
|
|
</Link>
|
|
|
|
<PostHeader frontMatter={frontMatter} estTime={readingTime(html)} />
|
|
|
|
<StyledMarkdown html={html} />
|
|
</div>
|
|
</div>
|
|
</MainLayout>
|
|
);
|
|
};
|
|
interface ProjectProps extends ParsedUrlQuery {
|
|
slug: string;
|
|
}
|
|
export const getStaticPaths: GetStaticPaths<ProjectProps> = async () => {
|
|
const paths = fs
|
|
.readdirSync(PROJECTS_PATH)
|
|
.map((path) => path.replace(/\.mdx?$/, ""))
|
|
.map((slug) => ({ params: { slug } }));
|
|
|
|
return {
|
|
paths,
|
|
fallback: false,
|
|
};
|
|
};
|
|
|
|
export const getStaticProps: GetStaticProps<MarkdownRenderingResult> = async ({
|
|
params,
|
|
}) => {
|
|
const markdownContent = getProjectContentBySlug(params?.slug as string);
|
|
return {
|
|
props: {
|
|
frontMatter: markdownContent.frontMatter,
|
|
html: markdownContent.content,
|
|
},
|
|
};
|
|
};
|
|
export default ProjectArticle;
|