/
page.tsx
69 lines (61 loc) · 1.57 KB
/
page.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
import Layout from '../components/Layout'
import { load } from 'outstatic/server'
import ContentGrid from '../components/ContentGrid'
import markdownToHtml from '../lib/markdownToHtml'
export default async function Index() {
const { content, allPosts, allProjects } = await getData()
return (
<Layout>
<div className="max-w-6xl mx-auto px-5">
<section className="mt-16 mb-16 md:mb-12">
<div
className="prose lg:prose-2xl home-intro"
dangerouslySetInnerHTML={{ __html: content }}
/>
</section>
{allPosts.length > 0 && (
<ContentGrid
title="Posts"
items={allPosts}
collection="posts"
priority
/>
)}
{allProjects.length > 0 && (
<ContentGrid
title="Projects"
items={allProjects}
collection="projects"
/>
)}
</div>
</Layout>
)
}
async function getData() {
const db = await load()
const page = await db
.find({ collection: 'pages', slug: 'home' }, ['content'])
.first()
const content = await markdownToHtml(page.content)
const allPosts = await db
.find({ collection: 'posts' }, [
'title',
'publishedAt',
'slug',
'coverImage',
'description',
'tags'
])
.sort({ publishedAt: -1 })
.toArray()
const allProjects = await db
.find({ collection: 'projects' }, ['title', 'slug', 'coverImage'])
.sort({ publishedAt: -1 })
.toArray()
return {
content,
allPosts,
allProjects
}
}