1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-01-03 10:25:00 +01:00

generate pages

This commit is contained in:
Matthias Kretschmann 2018-04-07 14:18:06 +02:00
parent 4f6158518b
commit 239efe8b0e
Signed by: m
GPG Key ID: 606EEEF3C479A91F
11 changed files with 161 additions and 40 deletions

19
.eslintrc Normal file
View File

@ -0,0 +1,19 @@
{
"plugins": ["react", "graphql"],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"modules": true
}
},
"env": {
"browser": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"rules": {
"quotes": ["error", "single"],
"semi": ["error", "never"]
}
}

View File

@ -4,12 +4,20 @@ module.exports = {
}, },
plugins: [ plugins: [
'gatsby-plugin-react-helmet', 'gatsby-plugin-react-helmet',
'gatsby-transformer-json',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'data',
path: `${__dirname}/data/`,
},
},
{ {
resolve: 'gatsby-plugin-sass', resolve: 'gatsby-plugin-sass',
options: { options: {
includePaths: [ includePaths: [
'./node_modules', `${__dirname}/node_modules`,
'./src/stylesheets', `${__dirname}/src/styles`,
], ],
}, },
}, },

View File

@ -1,7 +1,52 @@
/** const path = require('path')
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it // Implement the Gatsby API “createPages”. This is called once the
// data layer is bootstrapped to let plugins create pages from data.
exports.createPages = ({ boundActionCreators, graphql }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
const template = path.resolve('src/layouts/Project.js')
resolve(
graphql(`
{
allProjectsJson {
edges {
node {
title
slug
img
img_more
links {
Link
GitHub
Info
}
description
techstack
}
}
}
}
`).then(result => {
if (result.errors) {
reject(result.errors)
}
console.log(result)
result.data.allProjectsJson.edges.forEach(({ node }) => {
const slug = node.slug
createPage({
path: slug,
component: template,
context: { slug: slug },
})
})
resolve()
}))
})
}

View File

@ -7,11 +7,17 @@
"gatsby-link": "^1.6.39", "gatsby-link": "^1.6.39",
"gatsby-plugin-react-helmet": "^2.0.8", "gatsby-plugin-react-helmet": "^2.0.8",
"gatsby-plugin-sass": "latest", "gatsby-plugin-sass": "latest",
"gatsby-source-filesystem": "^1.5.28",
"gatsby-transformer-json": "^1.0.16",
"react-helmet": "^5.2.0", "react-helmet": "^5.2.0",
"react-markdown": "3.3.0", "react-markdown": "^3.3.0",
"react-transition-group": "^2.3.0" "react-transition-group": "^2.3.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^8.2.2",
"eslint": "^4.19.1",
"eslint-plugin-graphql": "^1.5.0",
"eslint-plugin-react": "^7.7.0",
"prettier": "^1.11.1" "prettier": "^1.11.1"
}, },
"scripts": { "scripts": {

View File

@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import './Content.css' import './Content.scss'
const Content = ({children}) => ( const Content = ({children}) => (
<div className="content"> <div className="content">

View File

@ -1,30 +1,27 @@
import React from 'react' import React from 'react'
import Link from 'react-router-dom/Link' import PropTypes from 'prop-types'
import Link from 'gatsby-link'
import FadeIn from '../atoms/FadeIn' import FadeIn from '../atoms/FadeIn'
import projects from '../../data/projects.json'
import images from '../../images' import images from '../../images'
import './Projects.scss' import './Projects.scss'
const Projects = () => ( const Projects = ({ data }) => {
<div className="projects full-width"> console.log(data)
{projects.map(project => ( const projects = data.allProjectsJson
<FadeIn key={project.slug}>
<Link
key={project.slug}
to={{ pathname: `/${project.slug}` }}
className="projects__project"
>
<h1 className="projects__project__title">{project.title}</h1>
<img return <div className="projects full-width">
className="projects__project__image" {projects.edges.map(({ node }) => <FadeIn key={node.slug}>
src={images[project.img]} <Link key={node.slug} to={`/${node.slug}`} className="projects__project">
alt={project.title} <h1 className="projects__project__title">{node.title}</h1>
/>
<img className="projects__project__image" src={images[node.img]} alt={node.title} />
</Link> </Link>
</FadeIn> </FadeIn>)}
))}
</div> </div>
) }
Projects.propTypes = {
data: PropTypes.object,
}
export default Projects export default Projects

View File

@ -1,4 +1,4 @@
import React, { Fragment } from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import Helmet from 'react-helmet' import Helmet from 'react-helmet'
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
@ -6,9 +6,13 @@ import Header from '../components/molecules/Header'
import Content from '../components/atoms/Content' import Content from '../components/atoms/Content'
import FullWidth from '../components/atoms/FullWidth' import FullWidth from '../components/atoms/FullWidth'
import images from '../images' import images from '../images'
import './Project.css' import './Project.scss'
const Project = ({ data }) => {
const project = data.allProjectsJson
console.log(project)
const Project = ({ project }) => {
const title = project.title const title = project.title
const img = project.img const img = project.img
const img_more = project.img_more const img_more = project.img_more
@ -17,7 +21,7 @@ const Project = ({ project }) => {
const techstack = project.techstack const techstack = project.techstack
return ( return (
<Fragment> <div>
<Helmet> <Helmet>
<title>{title}</title> <title>{title}</title>
</Helmet> </Helmet>
@ -67,12 +71,34 @@ const Project = ({ project }) => {
</Content> </Content>
</article> </article>
</main> </main>
</Fragment> </div>
) )
} }
Project.propTypes = { Project.propTypes = {
project: PropTypes.object data: PropTypes.object
} }
export default Project export default Project
export const query = graphql`
query ProjectQuery($slug: String!) {
allProjectsJson(slug: { eq: $slug }) {
edges {
node {
title
slug
img
img_more
links {
Link
GitHub
Info
}
description
techstack
}
}
}
}
`

View File

@ -1,14 +1,34 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types'
import Header from '../components/molecules/Header' import Header from '../components/molecules/Header'
import Projects from '../components/organisms/Projects' import Projects from '../components/organisms/Projects'
const Home = () => ( const Home = ({ data }) => (
<div> <div>
<Header /> <Header />
<main className="screen screen--home"> <main className="screen screen--home">
<Projects /> <Projects data={data} />
</main> </main>
</div> </div>
) )
Home.propTypes = {
data: PropTypes.object,
}
export default Home export default Home
export const query = graphql`
query IndexQuery {
allProjectsJson {
totalCount
edges {
node {
title
slug
img
}
}
}
}
`