/
test.tsx
52 lines (50 loc) · 1.36 KB
/
test.tsx
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
47
48
49
50
51
52
import path from 'path'
import { readMarkdownFile } from 'utils/getMarkdownFile'
import { readJsonFile } from 'utils/getJsonPreviewProps'
import { MarkdownContent } from 'components/layout'
import { EditLink } from 'components/layout/EditLink'
import { useCMS } from 'tinacms'
export default function TestPage({ guidesIndex, packagesIndex }) {
const cms = useCMS()
return (
<div>
<span>CMS is {cms.enabled ? 'Enabled' : 'Disabled'}</span>
<hr />
<button
onClick={() => {
fetch('/api/preview-test').then(() => window.location.reload())
}}
>
Enter preview mode
</button>
<hr />
<button
onClick={() => {
fetch('/api/reset-preview').then(() => window.location.reload())
}}
>
Exit preview mode
</button>
<hr />
<MarkdownContent
escapeHtml={false}
content={guidesIndex.data.markdownBody}
/>
<pre>{JSON.stringify(packagesIndex)}</pre>
</div>
)
}
export const getStaticProps = async ({ preview }) => {
return {
props: {
withoutGithub: true,
preview: !!preview,
guidesIndex: await readMarkdownFile(
path.resolve(process.cwd(), './content/guides/index.md')
),
packagesIndex: await readJsonFile(
path.resolve(process.cwd(), './content/packages.json')
),
},
}
}