mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-01-05 11:25:00 +01:00
Home refactor
This commit is contained in:
parent
b11367fcc2
commit
3ff8e67fac
@ -26,6 +26,13 @@ function truncate(n, useWordBoundary) {
|
|||||||
//
|
//
|
||||||
// Get GitHub repos
|
// Get GitHub repos
|
||||||
//
|
//
|
||||||
|
const gitHubConfig = {
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'kremalicious/portfolio',
|
||||||
|
Authorization: `token ${process.env.GITHUB_TOKEN}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getGithubRepos(data) {
|
async function getGithubRepos(data) {
|
||||||
let repos = []
|
let repos = []
|
||||||
let holder = {}
|
let holder = {}
|
||||||
@ -35,12 +42,7 @@ async function getGithubRepos(data) {
|
|||||||
const repoName = item.split('/')[1]
|
const repoName = item.split('/')[1]
|
||||||
const repo = await axios.get(
|
const repo = await axios.get(
|
||||||
`https://api.github.com/repos/${user}/${repoName}`,
|
`https://api.github.com/repos/${user}/${repoName}`,
|
||||||
{
|
gitHubConfig
|
||||||
headers: {
|
|
||||||
'User-Agent': 'kremalicious/portfolio',
|
|
||||||
Authorization: `token ${process.env.GITHUB_TOKEN}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
holder.name = repo.data.name
|
holder.name = repo.data.name
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
"remark": "^11.0.1",
|
"remark": "^11.0.1",
|
||||||
"remark-html": "^10.0.0",
|
"remark-html": "^10.0.0",
|
||||||
"remark-parse": "^7.0.1",
|
"remark-parse": "^7.0.1",
|
||||||
|
"shortid": "^2.2.15",
|
||||||
"suncalc": "^1.8.0",
|
"suncalc": "^1.8.0",
|
||||||
"vcf": "^2.0.6"
|
"vcf": "^2.0.6"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { Link, graphql } from 'gatsby'
|
import { Link, graphql } from 'gatsby'
|
||||||
|
import shortid from 'shortid'
|
||||||
import SEO from '../components/atoms/SEO'
|
import SEO from '../components/atoms/SEO'
|
||||||
import ProjectImage from '../components/atoms/ProjectImage'
|
import ProjectImage from '../components/atoms/ProjectImage'
|
||||||
import { ReactComponent as Images } from '../images/images.svg'
|
import { ReactComponent as Images } from '../images/images.svg'
|
||||||
@ -18,23 +19,16 @@ function getImageCount(images, slug) {
|
|||||||
return array.length
|
return array.length
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Home extends PureComponent {
|
Project.propTypes = {
|
||||||
static propTypes = {
|
node: PropTypes.shape({
|
||||||
data: PropTypes.object.isRequired,
|
slug: PropTypes.string.isRequired,
|
||||||
pageContext: PropTypes.object.isRequired
|
title: PropTypes.string.isRequired,
|
||||||
}
|
img: PropTypes.object.isRequired
|
||||||
|
}),
|
||||||
|
images: PropTypes.array.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
function Project({ node, images }) {
|
||||||
const { data, pageContext } = this.props
|
|
||||||
const projects = data.allProjectsYaml.edges
|
|
||||||
const images = data.projectImageFiles.edges
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<SEO />
|
|
||||||
|
|
||||||
<div className={styles.projects}>
|
|
||||||
{projects.map(({ node }) => {
|
|
||||||
const { slug, title, img } = node
|
const { slug, title, img } = node
|
||||||
const imageCount = getImageCount(images, slug)
|
const imageCount = getImageCount(images, slug)
|
||||||
|
|
||||||
@ -55,13 +49,30 @@ export default class Home extends PureComponent {
|
|||||||
</Link>
|
</Link>
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
})}
|
}
|
||||||
|
|
||||||
|
Home.propTypes = {
|
||||||
|
data: PropTypes.object.isRequired,
|
||||||
|
pageContext: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Home({ data, pageContext }) {
|
||||||
|
const projects = data.allProjectsYaml.edges
|
||||||
|
const images = data.projectImageFiles.edges
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SEO />
|
||||||
|
|
||||||
|
<div className={styles.projects}>
|
||||||
|
{projects.map(({ node }) => (
|
||||||
|
<Project key={shortid.generate()} node={node} images={images} />
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Repositories repos={pageContext.repos} />
|
<Repositories repos={pageContext.repos} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IndexQuery = graphql`
|
export const IndexQuery = graphql`
|
||||||
|
Loading…
Reference in New Issue
Block a user