-
-
Notifications
You must be signed in to change notification settings - Fork 542
/
Copy pathhomepage.tsx
executable file
·89 lines (81 loc) · 2.36 KB
/
homepage.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
/** @jsx jsx */
import { jsx } from "theme-ui"
import * as React from "react"
import type { HeadFC, PageProps } from "gatsby"
import { IGatsbyImageData, GatsbyImage } from "gatsby-plugin-image"
import Layout from "./layout"
import GridItem from "./grid-item"
import { itemListWrapperStyles, itemStyles } from "../styles/item-list"
import locales from "../locales"
import { visuallyHidden } from "../styles/utils"
import modifyGrid from "../utils/modify-grid"
import Seo from "./seo"
export type JodieHomepageProps = {
projects: {
nodes: {
slug: string
title: string
cover: {
childImageSharp: {
gatsbyImageData: IGatsbyImageData
}
}
__typename: "MdxProject"
}[]
}
pages: {
nodes: {
slug: string
title: string
cover: {
childImageSharp: {
gatsbyImageData: IGatsbyImageData
}
}
__typename: "MdxPage"
}[]
}
}
const Homepage: React.FC<PageProps<JodieHomepageProps>> = ({ data: { pages, projects } }) => {
const rawItems = [...pages.nodes, ...projects.nodes]
const items = modifyGrid(rawItems)
const itemsCount = items.length
let divisor = 9
for (let i = 0; i < itemsCount; i++) {
const quotient = itemsCount % divisor
const quotientAlt = (itemsCount - 1) % divisor
if (quotient === 0 || quotientAlt === 0) {
break
}
divisor -= 1
}
return (
<Layout>
<h1 sx={visuallyHidden} data-testid="page-title">
{locales.home}
</h1>
<div className={`item-list-wrapper`} sx={itemListWrapperStyles}>
<div className={`item-list div${divisor}`}>
{items.length > 0 ? (
items.map((item, index) => (
<GridItem to={item.slug} className="item" key={item.title} sx={itemStyles} data-testid={item.title}>
<GatsbyImage
loading={index === 0 ? `eager` : `lazy`}
image={item.cover.childImageSharp.gatsbyImageData}
alt=""
/>
<span>{item.title}</span>
</GridItem>
))
) : (
<div sx={{ padding: 3 }}>
No projects and pages found at the locations defined for "projectsPath" and "pagesPath"
</div>
)}
</div>
</div>
</Layout>
)
}
export default Homepage
export const Head: HeadFC = () => <Seo />