-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
index.tsx
89 lines (78 loc) · 2.15 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { DocsGrid, DocGridContent } from '../docs/[...slug]'
import { GetStaticProps } from 'next'
import { GithubError } from 'next-tinacms-github'
import React, { useState } from 'react'
import { createTocListener } from 'utils'
import { NextSeo } from 'next-seo'
import { openGraphImage } from 'utils/open-graph-image'
import { DocsLayout, MarkdownContent } from 'components/layout'
import { getJsonPreviewProps, readJsonFile } from 'utils/getJsonPreviewProps'
import path from 'path'
export default function PackageIndex(props) {
const excerpt = 'Packages for TinaCMS.'
const name = "Packages"
return (
<>
<NextSeo
title={name}
titleTemplate={'%s | TinaCMS Docs'}
description={excerpt}
openGraph={{
title: name,
description: excerpt,
images: [openGraphImage(name, ' | TinaCMS Docs')],
}}
/>
<DocsLayout navItems={props.docsNav}>
<DocsGrid>
<DocGridContent>
<h1>TinaCMS Packages</h1>
<hr />
<ul>
{props.packages.map( p => {
return (
<li><a href={p.link}>{p.name}</a></li>
)
}
)}
</ul>
</DocGridContent>
</DocsGrid>
</DocsLayout>
</>
)
}
export const getStaticProps: GetStaticProps = async function(props) {
try {
const { preview, previewData }: any = props
const previewProps = await getJsonPreviewProps(
'content/toc-doc.json',
preview,
previewData
)
const docsNavData = previewProps.props.file.data
const file = await readJsonFile(
path.resolve(process.cwd(), './content/packages.json')
)
const packagePages = file.packages.map( p => ({
name: p.name,
link: p.readme ? `/packages/${p.name}` : p.link
}))
return {
props: {
packages: packagePages,
docsNav: docsNavData
}
}
} catch (e) {
if (e instanceof GithubError) {
return {
props: {
previewError: { ...e }, //workaround since we cant return error as JSON
},
}
} else {
throw e
}
}
}