diff --git a/components/common/Markdown.tsx b/components/common/Markdown.tsx index 760e85066..849d39e1d 100644 --- a/components/common/Markdown.tsx +++ b/components/common/Markdown.tsx @@ -139,7 +139,6 @@ const Markdown: React.FC = ({ value, allowAll = false }) => { definition: () => null, heading: (props: any) => { const { children } = props; - console.log({ props }); return ( = ({ fundamentals }) => { - return ( - - - - - ); -}; - -export const getStaticProps = async () => { - const fundamentals = fs - .readFileSync(join(process.cwd(), "lib", "data", "sr", "fundamentals.md")) - .toString(); - - return { props: { fundamentals } }; -}; - -export default SalmonRunGuidePage; diff --git a/pages/sr/guide/[level].tsx b/pages/sr/guide/[level].tsx new file mode 100644 index 000000000..be2a02453 --- /dev/null +++ b/pages/sr/guide/[level].tsx @@ -0,0 +1,92 @@ +// import fundamentals from "/lib/data/sr/fundamentals.md"; +import { ListItem, OrderedList, UnorderedList } from "@chakra-ui/react"; +import { t } from "@lingui/macro"; +import Breadcrumbs from "components/common/Breadcrumbs"; +import Markdown from "components/common/Markdown"; +import MyContainer from "components/common/MyContainer"; +import SubText from "components/common/SubText"; +import fs from "fs"; +import { GetStaticPaths, GetStaticProps } from "next"; +import { join } from "path"; +import { Fragment } from "react"; + +interface Props { + text: string; + sections: { name: string; parts: string[] }[]; + level: string; +} + +const SalmonRunGuidePage: React.FC = ({ text, sections, level }) => { + return ( + + + Contents + + {sections.map((section) => ( + + + {section.name} + + + {section.parts.map((part) => ( + {part} + ))} + + + ))} + + + + ); +}; + +export const getStaticProps: GetStaticProps = async ({ params }) => { + const text = fs + .readFileSync( + join( + process.cwd(), + "lib", + "data", + "sr", + `${(params!.level as string).toLowerCase()}.md` + ) + ) + .toString(); + + return { + props: { + text, + level: params!.level as string, + sections: text + .split("\n") + .reduce((acc: { name: string; parts: string[] }[], line) => { + if (line.startsWith("# ")) { + acc.push({ name: line.replace("# ", ""), parts: [] }); + } + if (line.startsWith("## ")) { + acc[acc.length - 1].parts.push(line.replace("## ", "")); + } + + return acc; + }, []), + }, + }; +}; + +export const getStaticPaths: GetStaticPaths = async () => { + return { + paths: [ + { params: { level: "fundamentals" } }, + { params: { level: "advanced" } }, + ], + fallback: false, + }; +}; + +export default SalmonRunGuidePage;