1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-06-30 05:31:44 +02:00
portfolio/src/pages/index.jsx

108 lines
2.4 KiB
React
Raw Normal View History

2021-03-13 01:03:23 +01:00
import React from 'react'
2018-04-07 14:18:06 +02:00
import PropTypes from 'prop-types'
2018-06-21 21:06:53 +02:00
import { Link, graphql } from 'gatsby'
2019-11-10 15:29:23 +01:00
import shortid from 'shortid'
2018-11-25 00:15:02 +01:00
import SEO from '../components/atoms/SEO'
2019-11-07 23:54:33 +01:00
import ProjectImage from '../components/atoms/ProjectImage'
2021-03-13 16:19:24 +01:00
import { grid } from '../components/Layout.module.css'
2021-03-12 23:47:28 +01:00
import {
project as styleProject,
title as styleTitle,
imageCount as styleImageCount
} from './index.module.css'
2019-05-26 16:55:56 +02:00
import Repositories from '../components/organisms/Repositories'
2019-11-13 11:59:59 +01:00
import Icon from '../components/atoms/Icon'
2018-04-06 17:24:35 +02:00
2018-11-25 01:52:31 +01:00
function getImageCount(images, slug) {
let array = []
2018-11-24 17:36:16 +01:00
let slugWithoutSlashes = slug.replace(/\//g, '')
2018-11-25 00:15:02 +01:00
images.map(
({ node }) => node.name.includes(slugWithoutSlashes) && array.push(node)
)
2018-11-24 17:36:16 +01:00
return array.length
}
2019-11-10 15:29:23 +01:00
Project.propTypes = {
node: PropTypes.shape({
slug: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
img: PropTypes.object.isRequired
}),
images: PropTypes.array.isRequired
}
2018-05-04 01:58:43 +02:00
2019-11-10 15:29:23 +01:00
function Project({ node, images }) {
const { slug, title, img } = node
const imageCount = getImageCount(images, slug)
2018-11-25 00:15:02 +01:00
2019-11-10 15:29:23 +01:00
return (
2021-03-13 15:48:58 +01:00
<Link to={slug} className={styleProject} key={slug}>
<h1 className={styleTitle}>{title}</h1>
<ProjectImage image={img.childImageSharp.gatsbyImageData} alt={title} />
2018-05-04 01:58:43 +02:00
2021-03-13 15:48:58 +01:00
{imageCount > 1 && (
<small
className={styleImageCount}
title={`${imageCount} project images`}
>
<Icon name="Image" /> {imageCount}
</small>
)}
</Link>
2019-11-10 15:29:23 +01:00
)
}
2019-11-10 15:29:23 +01:00
Home.propTypes = {
data: PropTypes.object.isRequired,
pageContext: PropTypes.object.isRequired
}
2018-04-06 17:24:35 +02:00
2021-03-13 01:03:23 +01:00
export default function Home({ data, pageContext }) {
2019-11-10 15:29:23 +01:00
const projects = data.allProjectsYaml.edges
const images = data.projectImageFiles.edges
2019-05-26 16:55:56 +02:00
2019-11-10 15:29:23 +01:00
return (
<>
<SEO />
2021-03-13 16:19:24 +01:00
<div className={grid}>
2019-11-10 15:29:23 +01:00
{projects.map(({ node }) => (
<Project key={shortid.generate()} node={node} images={images} />
))}
</div>
<Repositories repos={pageContext.repos} />
</>
)
2018-04-07 14:18:06 +02:00
}
2018-04-30 01:18:54 +02:00
export const IndexQuery = graphql`
2018-07-11 15:54:32 +02:00
query {
2018-05-05 00:17:26 +02:00
allProjectsYaml {
2018-04-07 14:18:06 +02:00
edges {
node {
title
slug
2018-05-04 01:58:43 +02:00
img {
childImageSharp {
2021-03-13 13:57:05 +01:00
...ProjectImageTeaser
2018-05-04 01:58:43 +02:00
}
}
2018-04-07 14:18:06 +02:00
}
}
}
2019-04-14 20:01:09 +02:00
projectImageFiles: allFile(
filter: { absolutePath: { regex: "/portfolio/" } }
) {
edges {
node {
name
}
}
}
2018-04-07 14:18:06 +02:00
}
`