-
Notifications
You must be signed in to change notification settings - Fork 0
/
[slug].js
46 lines (40 loc) · 1.07 KB
/
[slug].js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { TinaMarkdown } from "tinacms/dist/rich-text";
import { Layout } from "../components/Layout";
import { useTina } from "tinacms/dist/react";
import { client } from "../.tina/__generated__/client";
export default function Home(props) {
// data passes though in production mode and data is updated to the sidebar data in edit-mode
const { data } = useTina({
query: props.query,
variables: props.variables,
data: props.data,
});
const content = data.page.body;
return (
<Layout>
<TinaMarkdown content={content} />
</Layout>
);
}
export const getStaticPaths = async () => {
const { data } = await client.queries.pageConnection();
const paths = data.pageConnection.edges.map((x) => {
return { params: { slug: x.node._sys.filename } };
});
return {
paths,
fallback: "blocking",
};
};
export const getStaticProps = async ({ params }) => {
const { data, query, variables } = await client.queries.page({
relativePath: `${params.slug}.mdx`,
});
return {
props: {
data,
query,
variables,
},
};
};