Skip to content

Commit f133a3f

Browse files
committed
Read docs from disk
1 parent 5b28402 commit f133a3f

File tree

5 files changed

+351
-7
lines changed

5 files changed

+351
-7
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["next/babel"],
3+
"plugins": [["styled-components", { "ssr": true }]]
4+
}

components/SideBar.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import React from "react";
22
import styled from "styled-components";
3+
import ReactMarkdown from "react-markdown";
4+
5+
const Sidebar = {
6+
Home: "",
7+
};
38

49
const Container = styled.div`
5-
margin: 2em 0;
10+
margin: 1em 0;
611
position: sticky;
712
top: 1em;
813
`;
@@ -14,8 +19,9 @@ const Item = styled.div`
1419
cursor: pointer;
1520
1621
&:hover {
17-
transition: 100ms;
18-
background: #0001;
22+
transition: 50ms;
23+
/* background: #0001; */
24+
transform: translateX(3px);
1925
color: #0972d4;
2026
}
2127
`;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"next": "10.0.8",
1212
"react": "17.0.1",
1313
"react-dom": "17.0.1",
14+
"react-markdown": "^5.0.3",
1415
"styled-components": "^5.2.1"
1516
},
1617
"devDependencies": {

pages/docs/[doc].tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { GetStaticProps, GetServerSideProps, GetStaticPaths } from "next";
2+
import fs from "fs/promises";
3+
import path from "path";
4+
import ReactMarkdown from "react-markdown";
5+
import React from "react";
6+
import { CenterContainer } from "../../components/CenterContainer";
7+
import { NavBar } from "../../components/NavBar";
8+
import { SideBar } from "../../components/SideBar";
9+
import styled from "styled-components";
10+
11+
const ARTICLES_PATH = path.join(process.cwd(), "articles");
12+
13+
interface Props {
14+
content: string;
15+
}
16+
17+
const Container = styled.div`
18+
display: grid;
19+
gap: 2em;
20+
grid-template-columns: 200px 1fr;
21+
`;
22+
23+
export default function DocPage(props: Props) {
24+
return (
25+
<>
26+
<NavBar />
27+
<CenterContainer style={{ margin: "2em 0" }}>
28+
<Container>
29+
<div>
30+
<SideBar />
31+
</div>
32+
<div style={{ overflow: "hidden" }}>
33+
<ReactMarkdown>{props.content}</ReactMarkdown>;
34+
</div>
35+
</Container>
36+
</CenterContainer>
37+
</>
38+
);
39+
}
40+
41+
export const getStaticProps: GetStaticProps<Props> = async function (props) {
42+
let file = path.join(ARTICLES_PATH, props.params!.doc + ".md");
43+
return {
44+
props: {
45+
content: await fs.readFile(file, "utf-8"),
46+
},
47+
};
48+
};
49+
50+
export const getStaticPaths: GetStaticPaths = async function () {
51+
let files = await fs.readdir(ARTICLES_PATH);
52+
return {
53+
paths: files.filter((e) => e.endsWith(".md")).map((e) => "/docs/" + e.slice(0, e.length - 3)),
54+
fallback: false,
55+
};
56+
};

0 commit comments

Comments
 (0)