Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby-image] improvements #2320

Merged
merged 34 commits into from
Oct 7, 2017
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5757507
Don't load images in SSR + fix loading for browsers not support Inter…
KyleAMathews Oct 3, 2017
21158f3
Publish
KyleAMathews Oct 3, 2017
d315257
Add gatsby-image to the using-wordpress example site
KyleAMathews Oct 3, 2017
0488bac
Merge remote-tracking branch 'origin/master' into gatsby-image-fixes
KyleAMathews Oct 4, 2017
ab3d1d9
Publish
KyleAMathews Oct 4, 2017
db235ca
Use gatsby-image in example sites
KyleAMathews Oct 5, 2017
f1d5745
Update TODO
KyleAMathews Oct 5, 2017
8deb4d9
Cache if have seen an image before so don't fadein + improve fadein t…
KyleAMathews Oct 5, 2017
65170b8
Merge branch 'master' into gatsby-image-fixes
KyleAMathews Oct 5, 2017
d437908
Deprecate responsiveSizes & responsiveResolution and use sizes/resolu…
KyleAMathews Oct 5, 2017
27ebbf9
Clean up API specification document a bit
KyleAMathews Oct 5, 2017
509c3c2
New pattern for adding fragments for queries
KyleAMathews Oct 6, 2017
d45895a
Add gatsby-image to www
KyleAMathews Oct 6, 2017
3a72f1a
Update yarn.lock
KyleAMathews Oct 6, 2017
91b8869
Try explicitely adding chokidar/fsevents per online discussions to se…
KyleAMathews Oct 6, 2017
abd8b7b
Update package.json again
KyleAMathews Oct 6, 2017
ab58334
Try removing yarn.lock
KyleAMathews Oct 6, 2017
c089b26
Try running install as development
KyleAMathews Oct 6, 2017
e57ccfb
Kill early check-versions while it's broken
KyleAMathews Oct 6, 2017
63347d8
Restore installing from yarn.lock
KyleAMathews Oct 6, 2017
047a6b6
Remove leftover console.log
KyleAMathews Oct 6, 2017
f12802f
"sizes" is being clobbered so use longer name
KyleAMathews Oct 6, 2017
7f8219e
Work around bug in webkit/blink browsers
KyleAMathews Oct 6, 2017
46f1925
Add fragments for gatsby-source-contentful + update using-contentful
KyleAMathews Oct 6, 2017
d5502fe
Fix backgroundColor prop
KyleAMathews Oct 6, 2017
8dabfd3
Try setting Netlify to install with node_env=development
KyleAMathews Oct 7, 2017
48b3ffa
Try try again
KyleAMathews Oct 7, 2017
fd6e3ca
Why won't this work???
KyleAMathews Oct 7, 2017
b58ca59
moer cleanups
KyleAMathews Oct 7, 2017
0174e03
Show backgroundColor for author avatar on blog posts
KyleAMathews Oct 7, 2017
5e4251a
Reset the z-index to 0 with new parent div
KyleAMathews Oct 7, 2017
07c22b3
Add first cut of documentation for gatsby-image
KyleAMathews Oct 7, 2017
89a6609
Copy tweaks
KyleAMathews Oct 7, 2017
e4e744d
Code comments
KyleAMathews Oct 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add fragments for gatsby-source-contentful + update using-contentful
  • Loading branch information
KyleAMathews committed Oct 6, 2017
commit 46f1925d20893f20561b24bea61d9da22ba86b3e
37 changes: 10 additions & 27 deletions examples/using-contentful/src/pages/image-api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react"
import Img from "gatsby-image"
import { rhythm } from "../utils/typography"

export default props => {
@@ -43,7 +44,6 @@ export default props => {
src
width
height
aspectRatio
}
}
}
@@ -68,12 +68,9 @@ export default props => {
You should prefer this operator over <code>resize</code>.
</p>
{assets.map(({ node: { title, resolutions } }) => (
<img
<Img
alt={title}
src={resolutions.src}
srcSet={resolutions.srcSet}
width={resolutions.width}
height={resolutions.height}
resolutions={resolutions}
style={{
marginRight: rhythm(1 / 2),
marginBottom: rhythm(1 / 2),
@@ -123,12 +120,9 @@ export default props => {
</a>
</p>
{assets.map(({ node: { title, resizing } }) => (
<img
<Img
alt={title}
src={resizing.src}
srcSet={resizing.srcSet}
width={resizing.width}
height={resizing.height}
resolutions={resizing}
style={{
marginRight: rhythm(1 / 2),
marginBottom: rhythm(1 / 2),
@@ -172,11 +166,9 @@ export default props => {
reaches.
</p>
{assets.map(({ node: { title, sizes } }) => (
<img
<Img
alt={title}
src={sizes.src}
srcSet={sizes.srcSet}
sizes={sizes.sizes}
sizes={sizes}
style={{
marginRight: rhythm(1 / 2),
marginBottom: rhythm(1 / 2),
@@ -219,24 +211,15 @@ export const pageQuery = graphql`
src
width
height
aspectRatio
}
resolutions(width: 100) {
width
height
src
srcSet
...GatsbyContentfulResolutions_noBase64
}
resizing: resolutions(width: 100, height: 100) {
width
height
src
srcSet
...GatsbyContentfulResolutions_noBase64
}
sizes(maxWidth: 613) {
sizes
src
srcSet
...GatsbyContentfulSizes_noBase64
}
}
}
12 changes: 2 additions & 10 deletions examples/using-contentful/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -90,11 +90,7 @@ export const pageQuery = graphql`
}
image {
resolutions(width: 75) {
base64
src
srcSet
height
width
...GatsbyContentfulResolutions
}
}
}
@@ -109,11 +105,7 @@ export const pageQuery = graphql`
}
image {
resolutions(width: 75) {
base64
src
srcSet
height
width
...GatsbyContentfulResolutions
}
}
}
4 changes: 1 addition & 3 deletions packages/gatsby-image/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from "react"
import PropTypes from "prop-types"

// TODO support adding node_modules/gatsby-image as place to scan for graphql fragments to gatsby-plugin-sharp and gatsby-source-contentful
// TODO add fragments here with and without base64 in fragments file so not included in pages.

const convertProps = props => {
let convertedProps = { ...props }
if (convertedProps.responsiveResolution) {
@@ -219,6 +216,7 @@ class Image extends React.Component {
style={{
position: `relative`,
overflow: `hidden`,
display: `inline-block`,
zIndex: 1,
width: image.width,
height: image.height,
1 change: 1 addition & 0 deletions packages/gatsby-source-contentful/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/gatsby-node.js
/fragments.js
/extend-node-type.js
/normalize.js
/fetch.js
2 changes: 1 addition & 1 deletion packages/gatsby-source-contentful/.npmignore
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ build/Release
node_modules
*.un~
yarn.lock
src
src/__tests__
flow-typed
coverage
decls
1 change: 1 addition & 0 deletions packages/gatsby-source-contentful/package.json
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
"bluebird": "^3.5.0",
"contentful": "^4.3.0",
"deep-map": "^1.5.0",
"fs-extra": "^4.0.2",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.4",
"qs": "^6.4.0"
10 changes: 4 additions & 6 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
@@ -342,7 +342,7 @@ exports.extendNodeType = ({ type }) => {
return {
resolutions: {
type: new GraphQLObjectType({
name: `ContentfulResponsiveResolution`,
name: `ContentfulResolutions`,
fields: {
base64: { type: GraphQLString },
aspectRatio: { type: GraphQLFloat },
@@ -382,7 +382,7 @@ exports.extendNodeType = ({ type }) => {
},
sizes: {
type: new GraphQLObjectType({
name: `ContentfulResponsiveSizes`,
name: `ContentfulSizes`,
fields: {
base64: { type: GraphQLString },
aspectRatio: { type: GraphQLFloat },
@@ -423,8 +423,7 @@ exports.extendNodeType = ({ type }) => {
},
},
responsiveResolution: {
deprecationReason:
`We dropped the "responsive" part of the name to make it shorter https://github.com/gatsbyjs/gatsby/pull/2320/`,
deprecationReason: `We dropped the "responsive" part of the name to make it shorter https://github.com/gatsbyjs/gatsby/pull/2320/`,
type: new GraphQLObjectType({
name: `ContentfulResponsiveResolution`,
fields: {
@@ -465,8 +464,7 @@ exports.extendNodeType = ({ type }) => {
},
},
responsiveSizes: {
deprecationReason:
`We dropped the "responsive" part of the name to make it shorter https://github.com/gatsbyjs/gatsby/pull/2320/`,
deprecationReason: `We dropped the "responsive" part of the name to make it shorter https://github.com/gatsbyjs/gatsby/pull/2320/`,
type: new GraphQLObjectType({
name: `ContentfulResponsiveSizes`,
fields: {
38 changes: 38 additions & 0 deletions packages/gatsby-source-contentful/src/fragments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable */
export const contentfulAssetResolutions = graphql`
fragment GatsbyContentfulResolutions on ContentfulResolutions {
base64
width
height
src
srcSet
}
`

export const contentfulAssetResolutionsNoBase64 = graphql`
fragment GatsbyContentfulResolutions_noBase64 on ContentfulResolutions {
width
height
src
srcSet
}
`

export const contentfulAssetSizes = graphql`
fragment GatsbyContentfulSizes on ContentfulSizes {
base64
aspectRatio
src
srcSet
sizes
}
`

export const contentfulAssetSizesNoBase64 = graphql`
fragment GatsbyContentfulSizes_noBase64 on ContentfulSizes {
aspectRatio
src
srcSet
sizes
}
`
37 changes: 37 additions & 0 deletions packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const _ = require(`lodash`)
const fs = require(`fs-extra`)

const normalize = require(`./normalize`)
const fetchData = require(`./fetch`)
@@ -166,3 +167,39 @@ exports.sourceNodes = async (

return
}

// Check if there are any ContentfulAsset nodes and if gatsby-image is installed. If so,
// add fragments for ContentfulAsset and gatsby-image. The fragment will cause an error
// if there's not ContentfulAsset nodes and without gatsby-image, the fragment is useless.
exports.onPreExtractQueries = async ({
store,
getNodes,
boundActionCreators,
}) => {
const program = store.getState().program

const nodes = getNodes()

if (!nodes.some(n => n.internal.type === `ContentfulAsset`)) {
return
}

let gatsbyImageDoesNotExist = true
try {
require.resolve(`gatsby-image`)
gatsbyImageDoesNotExist = false
} catch (e) {
// Ignore
}

if (gatsbyImageDoesNotExist) {
return
}

// We have both gatsby-image installed as well as ImageSharp nodes so let's
// add our fragments to .cache/fragments.
await fs.copy(
require.resolve(`gatsby-source-contentful/src/fragments.js`),
`${program.directory}/.cache/fragments/contentful-asset-fragments.js`
)
}