1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-02-01 20:39:45 +01:00

Merge pull request #27 from kremalicious/feature/gatsby-updates

package updates, put StaticQuery queries into variables
This commit is contained in:
Matthias Kretschmann 2018-09-06 15:11:23 +02:00 committed by GitHub
commit 373044a006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 258 additions and 296 deletions

View File

@ -1,5 +0,0 @@
version: "2"
checks:
method-lines:
config:
threshold: 50 # Gatsby's StaticQuery makes render functions pretty long

View File

@ -21,11 +21,11 @@
},
"dependencies": {
"file-saver": "^1.3.8",
"gatsby": "^2.0.0-rc.11",
"gatsby": "^2.0.0-rc.13",
"gatsby-image": "^2.0.0-rc.1",
"gatsby-plugin-manifest": "^2.0.2-rc.1",
"gatsby-plugin-matomo": "^0.5.0",
"gatsby-plugin-offline": "^2.0.0-rc.3",
"gatsby-plugin-offline": "^2.0.0-rc.4",
"gatsby-plugin-react-helmet": "^3.0.0-rc.1",
"gatsby-plugin-sass": "^2.0.0-rc.2",
"gatsby-plugin-sharp": "^2.0.0-rc.3",

View File

@ -4,11 +4,20 @@ import { StaticQuery, graphql } from 'gatsby'
import Logo from '../svg/Logo'
import styles from './LogoUnit.module.scss'
class LogoUnit extends PureComponent {
constructor(props) {
super(props)
const query = graphql`
query {
dataYaml {
title
tagline
}
}
`
this.state = { minimal: false }
class LogoUnit extends PureComponent {
state = { minimal: false }
static propTypes = {
minimal: PropTypes.bool
}
checkMinimal = () => {
@ -28,14 +37,7 @@ class LogoUnit extends PureComponent {
render() {
return (
<StaticQuery
query={graphql`
query {
dataYaml {
title
tagline
}
}
`}
query={query}
render={data => {
const meta = data.dataYaml
const { minimal } = this.state
@ -58,8 +60,4 @@ class LogoUnit extends PureComponent {
}
}
LogoUnit.propTypes = {
minimal: PropTypes.bool
}
export default LogoUnit

View File

@ -15,35 +15,37 @@ function truncate(n, useWordBoundary) {
)
}
const SEO = ({ project }) => (
<StaticQuery
query={graphql`
query {
dataYaml {
title
tagline
description
url
email
img {
childImageSharp {
resize(width: 980) {
src
}
}
const query = graphql`
query {
dataYaml {
title
tagline
description
url
email
img {
childImageSharp {
resize(width: 980) {
src
}
social {
Email
Blog
Twitter
GitHub
Dribbble
}
gpg
addressbook
}
}
`}
social {
Email
Blog
Twitter
GitHub
Dribbble
}
gpg
addressbook
}
}
`
const SEO = ({ project }) => (
<StaticQuery
query={query}
render={data => {
const meta = data.dataYaml

View File

@ -17,15 +17,17 @@ const TypekitScript = typekitID => (
</script>
)
const query = graphql`
query {
dataYaml {
typekitID
}
}
`
const Typekit = () => (
<StaticQuery
query={graphql`
query {
dataYaml {
typekitID
}
}
`}
query={query}
render={data => {
const { typekitID } = data.dataYaml

View File

@ -3,88 +3,43 @@ import { StaticQuery, graphql } from 'gatsby'
import FileSaver from 'file-saver'
import vCard from 'vcf'
const Vcard = () => (
<StaticQuery
query={graphql`
query {
dataYaml {
title
tagline
description
url
email
avatar {
childImageSharp {
original: resize {
src
}
}
const query = graphql`
query {
dataYaml {
title
tagline
description
url
email
avatar {
childImageSharp {
original: resize {
src
}
social {
Email
Blog
Twitter
GitHub
Dribbble
}
gpg
addressbook
}
}
`}
social {
Email
Blog
Twitter
GitHub
Dribbble
}
gpg
addressbook
}
}
`
const Vcard = () => (
<StaticQuery
query={query}
render={data => {
const meta = data.dataYaml
const constructVcard = () => {
const contact = new vCard()
const photoSrc = meta.avatar.childImageSharp.original.src
// first, convert the avatar to base64,
// then construct all vCard elements
toDataURL(
photoSrc,
dataUrl => {
// stripping this data out of base64 string is required
// for vcard to actually display the image for whatever reason
const dataUrlCleaned = dataUrl
.split('data:image/jpeg;base64,')
.join('')
contact.set('photo', dataUrlCleaned, {
encoding: 'b',
type: 'JPEG'
})
contact.set('fn', meta.title)
contact.set('title', meta.tagline)
contact.set('email', meta.email)
contact.set('url', meta.url, { type: 'Portfolio' })
contact.add('url', meta.social.Blog, { type: 'Blog' })
contact.set('nickname', 'kremalicious')
contact.add('x-socialprofile', meta.social.Twitter, {
type: 'twitter'
})
contact.add('x-socialprofile', meta.social.GitHub, {
type: 'GitHub'
})
const vcard = contact.toString('3.0')
downloadVcard(vcard)
},
'image/jpeg'
)
}
// Construct the download from a blob of the just constructed vCard,
// and save it to user's file system
const downloadVcard = vcard => {
const name = meta.addressbook.split('/').join('')
const blob = new Blob([vcard], { type: 'text/x-vcard' })
FileSaver.saveAs(blob, name)
}
const handleAddressbookClick = e => {
e.preventDefault()
constructVcard()
constructVcard(meta)
}
return (
@ -101,6 +56,43 @@ const Vcard = () => (
/>
)
// Construct the download from a blob of the just constructed vCard,
// and save it to user's file system
const downloadVcard = (vcard, meta) => {
const name = meta.addressbook.split('/').join('')
const blob = new Blob([vcard], { type: 'text/x-vcard' })
FileSaver.saveAs(blob, name)
}
const constructVcard = meta => {
const contact = new vCard()
const photoSrc = meta.avatar.childImageSharp.original.src
// first, convert the avatar to base64, then construct all vCard elements
toDataURL(
photoSrc,
dataUrl => {
// stripping this data out of base64 string is required
// for vcard to actually display the image for whatever reason
const dataUrlCleaned = dataUrl.split('data:image/jpeg;base64,').join('')
contact.set('photo', dataUrlCleaned, { encoding: 'b', type: 'JPEG' })
contact.set('fn', meta.title)
contact.set('title', meta.tagline)
contact.set('email', meta.email)
contact.set('url', meta.url, { type: 'Portfolio' })
contact.add('url', meta.social.Blog, { type: 'Blog' })
contact.set('nickname', 'kremalicious')
contact.add('x-socialprofile', meta.social.Twitter, { type: 'twitter' })
contact.add('x-socialprofile', meta.social.GitHub, { type: 'GitHub' })
const vcard = contact.toString('3.0')
downloadVcard(vcard, meta)
},
'image/jpeg'
)
}
// Helper function to create base64 string from avatar image
// without the need to read image file from file system
const toDataURL = (src, callback, outputFormat) => {

View File

@ -4,25 +4,25 @@ import { StaticQuery, graphql } from 'gatsby'
import { MoveIn } from '../atoms/Animations'
import styles from './Availability.module.scss'
class Availability extends PureComponent {
constructor(props) {
super(props)
const query = graphql`
query {
dataYaml {
availability {
status
available
unavailable
}
}
}
`
export default class Availability extends PureComponent {
static propTypes = { hide: PropTypes.bool }
render() {
return (
<StaticQuery
query={graphql`
query {
dataYaml {
availability {
status
available
unavailable
}
}
}
`}
query={query}
render={data => {
const { availability } = data.dataYaml
const { status, available, unavailable } = availability
@ -53,9 +53,3 @@ class Availability extends PureComponent {
)
}
}
Availability.propTypes = {
hide: PropTypes.bool
}
export default Availability

View File

@ -4,16 +4,18 @@ import { StaticQuery, graphql } from 'gatsby'
import SEO from '../atoms/SEO'
import Typekit from '../atoms/Typekit'
const query = graphql`
query {
dataYaml {
title
tagline
}
}
`
const Head = () => (
<StaticQuery
query={graphql`
query {
dataYaml {
title
tagline
}
}
`}
query={query}
render={data => {
const { title, tagline } = data.dataYaml

View File

@ -12,6 +12,20 @@ import Dribbble from '../svg/Dribbble'
import icons from '../atoms/Icons.module.scss'
import styles from './Networks.module.scss'
const query = graphql`
query {
dataYaml {
social {
Email
Blog
Twitter
GitHub
Dribbble
}
}
}
`
const NetworkIcon = props => {
switch (props.title) {
case 'Email':
@ -29,13 +43,14 @@ const NetworkIcon = props => {
}
}
class Network extends PureComponent {
constructor(props) {
super(props)
export default class Network extends PureComponent {
static propTypes = {
minimal: PropTypes.bool,
hide: PropTypes.bool
}
this.state = {
classes: styles.networks
}
state = {
classes: styles.networks
}
componentDidMount() {
@ -57,19 +72,7 @@ class Network extends PureComponent {
render() {
return (
<StaticQuery
query={graphql`
query {
dataYaml {
social {
Email
Blog
Twitter
GitHub
Dribbble
}
}
}
`}
query={query}
render={data => {
const meta = data.dataYaml
@ -92,10 +95,3 @@ class Network extends PureComponent {
)
}
}
Network.propTypes = {
minimal: PropTypes.bool,
hide: PropTypes.bool
}
export default Network

View File

@ -5,6 +5,26 @@ import Img from 'gatsby-image'
import FullWidth from '../atoms/FullWidth'
import styles from './ProjectNav.module.scss'
const query = graphql`
query {
allProjectsYaml {
edges {
node {
title
slug
img {
childImageSharp {
fluid(maxWidth: 500, quality: 85) {
...GatsbyImageSharpFluid_noBase64
}
}
}
}
}
}
}
`
const ProjectLink = ({ node }) => (
<Link className={styles.link} to={node.slug}>
<Img
@ -16,15 +36,9 @@ const ProjectLink = ({ node }) => (
</Link>
)
class ProjectNav extends Component {
constructor(props) {
super(props)
this.state = {
scrolledToCurrent: false
}
this.scrollToCurrent = this.scrollToCurrent.bind(this)
export default class ProjectNav extends Component {
state = {
scrolledToCurrent: false
}
componentDidMount() {
@ -54,25 +68,7 @@ class ProjectNav extends Component {
return (
<StaticQuery
query={graphql`
query {
allProjectsYaml {
edges {
node {
title
slug
img {
childImageSharp {
fluid(maxWidth: 500, quality: 85) {
...GatsbyImageSharpFluid_noBase64
}
}
}
}
}
}
}
`}
query={query}
render={data => {
const projects = data.allProjectsYaml.edges
@ -111,5 +107,3 @@ ProjectLink.propTypes = {
ProjectNav.propTypes = {
slug: PropTypes.string
}
export default ProjectNav

View File

@ -5,20 +5,20 @@ import Day from '../svg/Day'
import Night from '../svg/Night'
import styles from './ThemeSwitch.module.scss'
const ThemeToggle = props => (
const ThemeToggle = ({ dark }) => (
<span id="toggle" className={styles.checkboxContainer} aria-live="assertive">
<Day className={props.dark ? null : 'active'} />
<Day className={dark ? null : 'active'} />
<span className={styles.checkboxFake} />
<Night className={props.dark ? 'active' : null} />
<Night className={dark ? 'active' : null} />
</span>
)
class ThemeSwitch extends PureComponent {
constructor(props) {
super(props)
ThemeToggle.propTypes = {
dark: PropTypes.bool
}
this.state = { dark: null }
}
export default class ThemeSwitch extends PureComponent {
state = { dark: null }
isDark = () => this.state.dark === true
@ -78,9 +78,3 @@ class ThemeSwitch extends PureComponent {
)
}
}
ThemeToggle.propTypes = {
dark: PropTypes.bool
}
export default ThemeSwitch

View File

@ -1,62 +1,66 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import { StaticQuery, graphql } from 'gatsby'
import Vcard from '../atoms/Vcard'
import LogoUnit from '../atoms/LogoUnit'
import Networks from '../molecules/Networks'
import styles from './Footer.module.scss'
class Footer extends PureComponent {
constructor(props) {
super(props)
const query = graphql`
query {
# the package.json file
portfolioJson {
name
homepage
repository
bugs
}
this.state = { year: new Date().getFullYear() }
dataYaml {
title
gpg
}
}
`
const FooterMarkup = ({ meta, pkg, year }) => (
<footer className={styles.footer}>
<LogoUnit minimal />
<Networks minimal />
<p className={styles.footer__actions}>
<Vcard />
<a href={meta.gpg}>PGP/GPG key</a>
<a href={pkg.bugs}>Found a bug?</a>
</p>
<p className={styles.footer__copyright}>
<small>
&copy; {year} {meta.title} &mdash; All Rights Reserved
</small>
</p>
</footer>
)
FooterMarkup.propTypes = {
meta: PropTypes.object,
pkg: PropTypes.object,
year: PropTypes.number
}
export default class Footer extends PureComponent {
state = { year: new Date().getFullYear() }
render() {
return (
<StaticQuery
query={graphql`
query {
# the package.json file
portfolioJson {
name
homepage
repository
bugs
}
dataYaml {
title
gpg
}
}
`}
query={query}
render={data => {
const pkg = data.portfolioJson
const meta = data.dataYaml
return (
<footer className={styles.footer}>
<LogoUnit minimal />
<Networks minimal />
<p className={styles.footer__actions}>
<Vcard />
<a href={meta.gpg}>PGP/GPG key</a>
<a href={pkg.bugs}>Found a bug?</a>
</p>
<p className={styles.footer__copyright}>
<small>
&copy; {this.state.year} {meta.title} &mdash; All Rights
Reserved
</small>
</p>
</footer>
)
return <FooterMarkup year={this.state.year} pkg={pkg} meta={meta} />
}}
/>
)
}
}
export default Footer

View File

@ -7,12 +7,18 @@ import ThemeSwitch from '../molecules/ThemeSwitch'
import LogoUnit from '../atoms/LogoUnit'
import styles from './Header.module.scss'
class Header extends PureComponent {
constructor(props) {
super(props)
this.state = { minimal: false }
const query = graphql`
query {
dataYaml {
availability {
status
}
}
}
`
export default class Header extends PureComponent {
state = { minimal: false }
checkMinimal = () => {
const { isHomepage } = this.props
@ -34,15 +40,7 @@ class Header extends PureComponent {
return (
<StaticQuery
query={graphql`
query {
dataYaml {
availability {
status
}
}
}
`}
query={query}
render={data => {
const meta = data.dataYaml
@ -68,5 +66,3 @@ class Header extends PureComponent {
Header.propTypes = {
isHomepage: PropTypes.bool
}
export default Header

View File

@ -12,12 +12,11 @@ import './404.scss'
const giphyClient = giphyAPI('LfXRwufRyt6PK414G2kKJBv3L8NdnxyR')
const tag = 'fail-cat'
class NotFound extends Component {
constructor(props) {
super(props)
this.state = { gif: '' }
export default class NotFound extends Component {
state = { gif: '' }
this.handleClick = this.handleClick.bind(this)
static propTypes = {
location: PropTypes.object
}
componentDidMount() {
@ -36,7 +35,7 @@ class NotFound extends Component {
})
}
handleClick(e) {
handleClick = e => {
e.preventDefault()
this.getRandomGif()
}
@ -64,9 +63,3 @@ class NotFound extends Component {
)
}
}
NotFound.propTypes = {
location: PropTypes.object
}
export default NotFound