1
0
Fork 0
blog/src/pages/index.tsx

84 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-07-19 13:31:27 +02:00
import { graphql, PageProps } from 'gatsby'
2021-02-28 02:21:28 +01:00
import React, { ReactElement } from 'react'
2020-07-08 01:31:03 +02:00
import { Post } from '../@types/Post'
2021-02-28 02:21:28 +01:00
import SEO from '../components/atoms/SEO'
2020-07-19 13:31:27 +02:00
import PostTeaser from '../components/molecules/PostTeaser'
2021-02-28 02:21:28 +01:00
import { PhotoThumb } from '../components/templates/Photos'
2020-07-19 13:31:27 +02:00
import PostMore from '../components/templates/Post/More'
2021-03-13 04:11:44 +01:00
import { section, articles, articlesLast, photos } from './index.module.css'
2020-07-08 01:31:03 +02:00
2021-02-28 04:09:56 +01:00
export default function Home({ data }: PageProps): ReactElement {
2020-07-08 01:31:03 +02:00
return (
2020-07-19 13:31:27 +02:00
<>
2021-02-28 02:21:28 +01:00
<SEO />
2021-03-13 04:11:44 +01:00
<section className={section}>
<div className={articles}>
2021-02-28 04:09:56 +01:00
{(data as any).latestArticles.edges
2021-02-28 23:45:27 +01:00
.slice(0, 2)
2021-02-28 02:21:28 +01:00
.map(({ node }: { node: Post }) => (
2021-02-28 04:09:56 +01:00
<PostTeaser key={node.id} post={node} hideDate />
2021-02-28 02:21:28 +01:00
))}
</div>
2021-03-13 04:11:44 +01:00
<div className={`${articles} ${articlesLast}`}>
2021-02-28 04:09:56 +01:00
{(data as any).latestArticles.edges
2021-03-04 22:53:35 +01:00
.slice(2, 8)
2021-02-28 02:21:28 +01:00
.map(({ node }: { node: Post }) => (
2021-02-28 04:09:56 +01:00
<PostTeaser key={node.id} post={node} hideDate />
2021-02-28 02:21:28 +01:00
))}
2020-07-19 13:31:27 +02:00
</div>
2021-02-28 23:13:31 +01:00
<PostMore to="/archive">All Articles</PostMore>
2020-07-19 13:31:27 +02:00
</section>
2021-03-13 04:11:44 +01:00
<section className={section}>
<div className={photos}>
2021-02-28 04:09:56 +01:00
{(data as any).latestPhotos.edges.map(({ node }: { node: Post }) => (
<PhotoThumb key={node.id} photo={node} />
))}
2020-07-19 13:31:27 +02:00
</div>
2021-02-28 23:13:31 +01:00
<PostMore to="/photos">All Photos</PostMore>
2020-07-19 13:31:27 +02:00
</section>
</>
2020-07-08 01:31:03 +02:00
)
}
export const homeQuery = graphql`
{
2020-07-11 11:42:37 +02:00
latestArticles: allMarkdownRemark(
2021-02-28 04:50:05 +01:00
filter: { fields: { type: { ne: "photo" } } }
sort: { fields: { date: DESC } }
2021-03-04 22:53:35 +01:00
limit: 8
2020-07-08 01:31:03 +02:00
) {
edges {
node {
2020-07-19 13:31:27 +02:00
...PostTeaser
2020-07-08 01:31:03 +02:00
}
}
}
latestPhotos: allMarkdownRemark(
2021-02-28 04:50:05 +01:00
filter: { fields: { type: { eq: "photo" } } }
sort: { fields: { date: DESC } }
2021-02-28 02:21:28 +01:00
limit: 12
2020-07-08 01:31:03 +02:00
) {
edges {
node {
id
frontmatter {
title
image {
childImageSharp {
2020-07-19 13:31:27 +02:00
...PhotoFluidThumb
2020-07-08 01:31:03 +02:00
}
}
}
fields {
slug
2021-02-28 22:14:36 +01:00
type
2020-07-08 01:31:03 +02:00
}
}
}
}
}
`