forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
46 lines (43 loc) · 1.12 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
import Link from 'next/link'
import React from 'react'
import { fetchGraphQL, gql } from '../utils'
type Author = { id: string, name: string, posts: { id: string, slug: string, title: string }[] }
export default function Index ({ authors }: { authors: Author[] }) {
return (
<>
<h1>Keystone Blog Project - Home</h1>
<ul>
{authors.map(author => (
<li key={author.id}>
<h2>
<Link href={`/author/${author.id}`}>{author.name}</Link>
</h2>
<ul>
{author.posts.map(post => (
<li key={post.id}>
<Link href={`/post/${post.slug}`}>{post.title}</Link>
</li>
))}
</ul>
</li>
))}
</ul>
</>
)
}
export async function getStaticProps () {
const data = await fetchGraphQL(gql`
query {
authors {
id
name
posts(where: { status: { equals: published } }, orderBy: { publishDate: desc }) {
id
slug
title
}
}
}
`)
return { props: { authors: data.authors }, revalidate: 30 }
}