-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathBlogRoute.res
More file actions
35 lines (30 loc) · 1.01 KB
/
BlogRoute.res
File metadata and controls
35 lines (30 loc) · 1.01 KB
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
type loaderData = {posts: array<BlogApi.post>, category: Blog.category}
let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
let showArchived = request.url->String.includes("archived")
let posts = async () =>
(await MdxFile.loadAllAttributes(~dir="markdown-pages/blog"))
->Array.map(BlogLoader.transform)
->Array.toSorted((a, b) => {
a.frontmatter.date->DateStr.toDate > b.frontmatter.date->DateStr.toDate ? -1.0 : 1.0
})
let posts: array<BlogApi.post> = (await posts())->Array.filter(post => {
post.archived == showArchived
})
let data = {posts, category: showArchived ? Archived : All}
data
}
@react.component
let default = () => {
let {posts, category} = ReactRouter.useLoaderData()
<>
<Meta
siteName="ReScript Blog"
title={`${switch category {
| All => "All Posts"
| Archived => "Archived Posts"
}} | ReScript Blog`}
description="News, Announcements, Release Notes and more"
/>
<Blog posts category />
</>
}